The PO file format is part of the gettext
internationalization and localization system commonly used in Unix-like systems. This system includes tools to ease the translation work.
This recipe demonstrates how to use these tools to help translate our addon modules. We want to use it on a custom module, so my_module
created in Chapter 3, Creating Odoo Modules is a good candidate. But feel free to replace it with some other custom module you have at hand, replacing the recipe's my_module
references as appropriate.
To manage the translation from the command line, assuming that your Odoo installation is at ~/odoo-work/odoo
, follow these steps:
odoo_es.po
we should write the following code:$ cd ~/odoo-work/odoo # Use the path to your Odoo installation $ find ./ -name es_ES.po | xargs msgcat --use-first | msgattrib --translated --no-fuzzy -o ./odoo_es.po
$ ./odoo.py -d mydb --i18n-export=my_module.po --modules=my_module $ mv my_module.po ./addons/my_module/i18n/my_module.pot
$ msgmerge --compendium ./odoo_es.po -o ./addons/my_module/i18n/es_ES.po /dev/null ./addons/my_module/i18n/my_module.pot
$ mv ./addons/my_module/i18n/es_ES.po /tmp/my_module_es_old.po $ msgmerge --compendium ./odoo_es.po -o./addons/my_module/i18n/es_ES.po /tmp/my_module_es_old.po ./addons/my_module/i18n/my_module.pot $ rm /tmp/my_module_es_old.po
$ msgattrib --untranslated ./addons/my_module/i18n/es_ES.po
Step 1 of the preceding section calls odoo.py
with the --i18n-export
option. You need to specify a database on the command line, even if one is specified in the configuration file and the --modules
option, with a comma separated list of modules to export the translation for.
Step 2 uses commands from the gettext toolbox to create a translation compendium for the chosen language, Spanish in our case. It works by finding all the es_ES.po
files in the Odoo code base, and passing them to the msgcat
command. We use the --use-first
flag to avoid conflicting translations (there are a few in the Odoo code base). The result is passed to the msgattrib
filter. We use the --translated
option to filter out the untranslated entries and the --no-fuzzy
option to remove the fuzzy translations. We then save the result in odoo_es.po
.
Step 3 creates a translation file using the translated values for texts already found in the compendium. The msgmerge
command is used with the --compendium
option to find in the compendium files the msgid
lines matching those in the translation template file generated in Step 1. The result is saved in the es_ES.po
file.
If you have a pre-existing .po
file for your addon with translations you would like to preserve, then you should rename it and replace the /dev/null
argument with this file. The rename is required to avoid using the same file both for input and output.
This recipe only skims the rich tools of the GNU gettext toolbox. Full coverage is well beyond the scope of this book. If you are interested, the GNU gettext documentation contains a wealth of precious information about PO file manipulation, and is available at http://www.gnu.org/software/gettext/manual/gettext.html.
18.188.10.246