Babel/distutils commands to help with managing Javascript translations.
Project description
doublespeak
Doublespeak lets you extract translateable messages in Javascript into separate PO files and then lets you compile them to JSON files that can for example be used with gettext.js
Motivation
Many modern Python web applications also include a significant amount of translatable strings in Javascript.
Because this Javascript code runs in the browser, instead of on the server where the Python code runs, it’s necessary to have its translateable messages in separate gettext PO files, from which you can then generate JSON/Javascript translation files to load in your browser.
Unfortunately, Babel, which provides distutils commands to create messages catalogs, and extract and compile messages, doesn’t allow you to create different catalogs for the same language in one package.
Doublespeak lets you do this, by providing new Babel/distutils commands that you can use to extract translateable messages from Javascript, and keep them separatele from the rest of your application’s translations.
New distutils commands:
The new distutils commands made available by doublespeak, are:
init_js_catalog - Initialize a new gettext catalog, specifically for JS messages.
extract_js_messages - Extract messages from JS and put them in the catalog.
update_js_catalog - Update an existing catalog with messages from newer JS code.
compile_js_catalog - Create the compiled .mo and JSON files from the .po files
Users of Babel, will notice that these commands are very similar to the ones provided by Babel:
init_catalog
extract_messages
update_catalog
compile_catalog
Some of the doublespeak commands are simply wrappers around Babel commands. The benefit they provide is that you can configure them independently from the Babel commands, for example in your setup.cfg file.
Configuration
Here’s an example setup.cfg file, which demonstrates how you can configure the standard Babel commands and the new Doublespeak commands:
[compile_catalog] # Change to a relevant domain domain = mypackage directory = src/mypackage/i18n/locales [compile_js_catalog] # Note that the Javascript files have a different domain. You'll need to use # this domain in your Javascript code, instead of using the domain above, # declared for the Python code. domain = mypackagejs # Contrary to compile_catalog, this commands takes both input and output directories, so that you can write the JSON translation files to a separate directory, where you might have the rest of your Javascript code. input_dir = src/mypackage/i18n/locales output_dir = src/mypackage/browser/resources/js/i18n [extract_messages] # Change to your organisation copyright_holder = Acme Inc. output_file = src/mypackage/i18n/locales/en/LC_MESSAGES/mypackage.po charset = UTF-8 add-comments = i18n [extract_js_messages] keywords = __ no-default-keywords = True copyright_holder = Acme Inc. output_file = src/mypackage/i18n/locales/en/LC_MESSAGES/mypackagejs.po charset = UTF-8 add-comments = i18n [init_catalog] domain = mypackage input_file = src/mypackage/i18n/locales/en/LC_MESSAGES/mypackage.po output_dir = src/mypackage/i18n/locales [init_js_catalog] domain = mypackagejs input_file = src/mypackage/i18n/locales/en/LC_MESSAGES/mypackagejs.po output_dir = src/mypackage/i18n/locales [update_catalog] domain = mypackage input_file = src/mypackage/i18n/locales/en/LC_MESSAGES/mypackage.po output_dir = src/mypackage/i18n/locales [update_js_catalog] domain = mypackagejs input_file = src/mypackage/i18n/locales/en/LC_MESSAGES/mypackagejs.po output_dir = src/mypackage/i18n/locales
Changes
0.3 (2016-03-07)
The output file javascript is jshint happy now.
0.2 (2016-03-04)
Simplify the generated Javascript translations files.
Add the “output-prefix” option to prefix the filenames of generated language .js files, defaults to ‘’.
Add ‘statistics’ and ‘use-fuzzy’ to be on par with Babel’s compile_catalog.
Build js files based on .po files instead of .mo files.
0.1 (2016-02-26)
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.