Native “.desktop” file support in gettext

The “.desktop” file format is simple, but it is a pain for translation tools such as gettext, which assumes that every output file (MO file, Java .properties file, etc) is generated for a single locale.

A translated .desktop file looks like:

[Desktop Entry]
Name[fr]=(French translation of "foo")
Name[de]=(German translation of "foo")

As you see, it mixes up the translations in multiple locales. This does not naturally fit in the current xgettext/msgfmt workflow. Traditionally, application developers have to use a wrapper script (aka intltool) to deal with this.

On the other hand, there has been a long-standing request to support the .desktop file format in gettext, to eliminate the extra dependency. So, I decided to give it a try. With the current patch set, you can extract translatable strings with xgettext as usual:

$ xgettext yourapp.desktop -o yourapp.pot

It doesn’t have much difference with intltool-extract, but xgettext properly interprets character escapes (\s, \n, \t, \r) and lists (foo;bar;baz;). This could prevent translation errors such as missing ‘;’ at the end of a list value.

Then, you can merge translations back to a .desktop file with msgfmt, one locale at a time:

$ msgfmt --desktop --locale=fr -o fr.desktop fr.po
$ msgfmt --desktop --template=fr.desktop --locale=de -o de.desktop de.po
$ msgfmt --desktop --template=yo.desktop --locale=zh -o yourapp.desktop zh.po

It could be inefficient, as it requires writing entire file for each locale, while intltool-merge processes multiple locales at once. However, I don’t think it would be an issue, since .desktop files are usually small.

I’d like to land this in the next release, so GNOME3 applications can be localized without intltool (perhaps you might remember that gettext recently got support for GtkBuilder and GSettings schema). I’ve created a sample project using those features, based on GTK+ application tutorial.

GHM 2013

I’m just back home after four weeks in Europe. The stay ended with the 7th GHM (GNU Hackers’ Meeting) at IRILL in Paris, France. As usual, the meeting was cosy and warm, but this time quite a few people (around 40) attended. The topics varied from kernel (Hurd), compiler (GDC), distribution (Guix), network protocol (GNUnet), accessibility, Emacs, statistics (PSPP), and free software activism (April), and all the talks were very interesting. Also, as a newbie GNU maintainer, I got some good discussions out there, including one with Patrice Dumas on translation of texinfo files using the Texinfo XML format.

Luca preparing the opening
Luca preparing the opening

Thanks to the organizers, speakers, and attendees. Thanks again to GNOME Foundation for allowing me to attend another conference with the GUADEC travel sponsorship.