A sample program to learn and test the I18N python library, using babel with integration with Distutils/Setuptools
Prerequirements:
pip install babel
-
Prepare your program to take into account I18N (see source file as an example)
-
extract the translatable objects to generate the portable objects template:
python setup.py extract_messages
- Prepare the portable object for a new language starting from template:
python setup.py init_catalog --locale <language>
-
Edit the portable object file
testi18n/locale/<language>/messages.po
completing the empty or fuzzymsgstr
fields. -
Compile the portable object files:
- Single language:
python setup.py compile_catalog --locale <language>
- All languages:
python setup.py compile_catalog
Portable object for US english and italian already available.
- Compile the portable object files for the available languages:
python setup.py compile_catalog --locale en_US
python setup.py compile_catalog --locale it_IT
- Run the program:
python testi18n/testi18n.py
If the source files are modified and strings are added or modified, the template can be updated with the usual extract command:
python setup.py extract_messages
After this the existing portable object files can be updated using the update command:
python setup.py update_catalog
After this the po
files shall be updated to translate the new strings (fuzzy translations are provided).
- To understand if there is a better way to update language for classes or subpackages (see comments in
trclass.py
).