Inkscape, like other projects, uses some custom XML files for configuration of various things throughout. In some of those cases, the XML contains strings that are user visible, and thus must be translated. So, I set off on a path to do this. Knowing that intltool could help (and was designed for it) I knew it was possible, but didn't know how. It's simple, but I couldn't find anyone to tell me, hopefully those who come behind me will find this page in their Google search.

The specific files that I'm talking about are called INX files, which define extensions to Inkscape. These files define technical aspects like how to execute the functionality, but also descriptions, names of file types, and GUI strings to be displayed in dialogs. A mix of content, but with some of it being placed for direct user interaction. In Inkscape CVS there is a directory that contains most of the INX files.

To get the strings out of the XML files, they must be put into the POTFILES.in file in the /po directory of the tree. Inside this file commands can be given to intltool for how to handle the translation, and the individual files. The commands to intltool are surrounded by brackets [ ] and removed for gettext. To specify that a file is XML the following should appear before its listing in POTFILES.in: [type: gettext/xml]. This tells intltool to convert this file, an xml file, into a header file that gettext can understand before running gettext on it. You can see how this is done in Inkscape's POTFILES.in.

In order to mark which strings should be translated intltool uses an underscore ('_') at the beginning of the attribute or the name of the tag. So something like <mytext>Text</mytext> would get converted to <_mytext>Text</_mytext>. Or <mytag attr="text"/> would be converted to <mytag _attr="text"/>. Those strings are then pulled out of the XML file, and placed in the po files for translation.

Now, you have some choices. Intltool will support merging those translations back into the XML files by making a set files each with a different language inside of it. I did not do this. Because I had control over the XML parser, I changed it to handle the underscores on various tags and attributes, and run those through the standard _( ) function in C. This works well for Inkscape, but might not work for other users, especially if you have restrictions on changing the way the XML is parsed.

All in all, I hope this saves someone from reading through source code, tons of Google searchers, and some guessing. Oh, the though of doing this without the source code, ewww.


posted Dec 8, 2005 | permanent link