How would you go about internationalizing a Google App Engine webapp application using BABEL? I am looking here for all the stages:
- Marking the strings to be translated.
- Extracting them.
- Traslating
- Configuring your app to load the right language requested by the browser
1) use _() (or gettext()) in your code and templates. Translated strings set in the module globals or class definitions should use some form of lazy gettext(), because i18n won't be available when the modules are imported.
2) Extract all translations using pybabel. Here we pass two directories to be scanned: the templates dir and the app dir. This will create a messages.pot file in the /locale directory with all strings found in these directories. babel.cfg is the extraction configuration that varies depending on the template engine you use:
3) Initialize a directory for each language. This is done only once. Here we initialize three translations, en_US, es_ES and pt_BR, and use the messages.pot file created on step 2:
Translate the messages. They will be in .mo files in each translation directory. After all locales are translated, compile them:
Later, if new translations are added, repeat step 2 and update them using the new .pot file:
Then translate the new strings and compile the translations again.
4) The strategy here may vary. For each request you must set the correct translations to be used, and probably want to cache loaded translations to reuse in subsequent requests.