Andy's insights

Opinions, thoughts, archivements

Wed, 21 Apr 2010

Javascript scanner for xgettext

I’ve spend quite a few hours to build Gettext support into our huge Javascript application at work. One missing part was a Javascript scanner for the xgettext command.

After looking into the source I decided to extend the Gettext utility by myself. (After all I read the Dragon Book ).

It was quite simple to build a Javascript scanner module based on the existing Python scanner. All scanners don’t try to fully parse the source code but to only parse as much as needed to divide comments from code and identify the gettext function calls (_("...")) and extract it’s argument(s).

The first version already ran through our code base of about 40k lines without any errors. But running it on another project revealed that I need also to identify regular expression statements like /a"b'c/. If the RegExp statement contains unbalanced string quotation marks (’ or “) then the scanner barks and misses following translateable strings. So I spend more time fixing those special cases. The scanner is now ready to test in production environments.

My next step is to port back the current code to 0.17 and fix the symbol error in this backport that prevents to compile it on ELF based systems.

If you are interrested, the module can be obtained from my public GIT repository at github:

I’m still trying to get it upstream into the gettext distribution. So far I got no reaction, but I’m patient. At least other possible users asked my about this new feature.

posted at: 23:41 | path: /development | permanent link to this entry