Internationalisation of a Gramps addon plug-in

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.

In the 183 folders in my .gramps/gramps52/plugins folder, there were 27 with po subfolders and only 22 with template.pot files. And those also had a variety of -local.po language files. Others had locale/<language code>/LC_MESSAGES/addon.mo files.

If you search the addons-source for po/template.pot files, there are 120 matches. And it looks like the make.py used to build the downloads and addons-xx.json explicitly removes the template.pot.

Is this counter-productive for getting new language translations volunteered and committed?

This is confusing, I think you have made a special installation.
in my .gramps/gramps52/plugin there is no po directory and no *-local.po file.
And in the addons-source I have 129 po directories, and 129 of them have a template.pot file.
What I noticed when I made the translation to danish for the plugins, was that sometimes the template.pot file did not include all the strings, which needed to be translated, and these strings was in some of the other language .po file.
I found that the make script (sometimes ?), created a new template.pot file, but who will run the make script if you only need poedit and template.pot to create your local translation?
And how will the translators be notified that a new version of a plugin has new strings in it?

So two things would be beneficial for translating plugins

  1. Make sure that the template.pot file always reflects the current version of the plugin
  2. Have a script that checks that a specific po file have all the strings from the template.pot file.