howto internationalize an addon plug-in
There are probably several ways to do this, but I will describe how I have internationalized the HistContext addon gramplet - using linux as my development platform
The development
You have to mark all the strings that will need translation (in the Python module files and the Gramps Plugin Registration file) using a special format,
use underscore and parentheses, like this:
opt = BooleanListOption(_(“Select from files”))
When you are done with the development, you will need to create a template.pot
file. It can be done this way:
In the directory of your gramplet run:
xgettext *.py
mkdir po
mv messages.po po/template.pot
And now you have made your gramplet translatable
Translation
You need to have an account on github.com and you need to have added an ssh key to that account.
I have then used the following commands to get a copy of the gramplet:
cd
mkdir gramps
cd gramps
git clone git@github.com:gramps-project/addons-source.git
Now you can make the translation, I use poedit for that.
The template file will be:
~/gramps/addons-source/HistContext/po/template.pot
poedit will, depending on your language propose a file name. This will however, not be the one, gramps will be using da-local.po
for Danish. For French, it will be fr-local.po
When you have saved the po
file, poedit will automatically create a .mo
file.
In my case, a da-local.mo
- this file can be used for testing.
update the po file
If you have an existing po file, and the template.pot has changed, you can do an update with the following command in the po directory:
msgmerge da-local.po template.pot > da-local.new
mv da-local.new da-local.po
Testing
Change directory to the plugin directory of a working Gramps, and create the locale directories:
cd ~/.gramps/gramps52/plugins/HistContext/
mkdir -p locale/da/LC_MESSAGES
cp ~/gramps/addons-source/HistContext/po/da-local.mo locale/da/LC_MESSAGES/addon.mo
And now, your translation should be used in the gramplet when starting Gramps in your language.
Just a little reminder: You can start Gramps in a specific language from the commandline:
LANG=da_DK.UTF-8
LANGUAGE=da_DK.UTF-8 gramps
Miscellaneous
All references to “da” should be replaced by your language, and all references of HistContext should be replaced by your gramplet name.