To extract the translation strings from JavaScript files, you need to use the xgettext tool. Unfortunately this tool still does not have native support for JavaScript. The C extractor comes pretty close, but JavaScript code needs some preprocessing (into fake C code) before it’s safe to use this.
If you have run buildout, the preprocessor is installed as part of a package called JsLex, in bin/jslex_prepare. First run this against all JavaScript files that need preparation for xgettext, like this:
bin/jslex_prepare src/obviel/obviel-forms.js
This will create a new file in src/obviel named obviel-forms.jslex. This file is only needed during xgettext extraction, so can be thrown away again.
Once we have this file, we need to use xgettext to extract its translation strings into a .pot file:
xgettext -L C -d obviel-forms --keyword=_ obviel-forms.jslex -o obviel-forms.pot
What are the command line arguments for?
Once there is a .pot file, you can turn it into a specific file that contains the translations for a language, in this example, Dutch:
msginit -l nl_NL -i obviel-forms.pot -o obviel-forms-nl.po
Now use the installed pojson script to transform the .po file into a obviel-forms-nl.js file:
bin/pojson convert -j obviel-forms src/obviel/obviel-forms-nl.po > src/obviel/obviel-forms-nl.js
The obviel-forms-nl.js file contains the translated messages in a form consumable by JsGetText. This file needs to be included before obviel-forms.js to make the translations take effect.
The magic command to create the *.pot file from .jslex files:
xgettext -L C -d obviel-forms --keyword=_ src/obviel/obviel-forms.jslex src/obviel/obviel-forms-datepicker.jslex src/obviel/obviel-forms-autocomplete.jslex -o src/obviel/obviel-forms.pot
It would be nice to automate the whole procedure (perhaps using Fanstatic?). It would also be nice if more than one language could be loaded into the client at once.