How do I make my application find the gettext translations?

Viewed 93

I'm trying out gettext translations for xnec2c.

gettext generates a po/xnec2c.pot file at build time and I have translated that .pot file to de_DE and placed it in /usr/share/locale/de_DE/LC_MESSAGES/xnec2c.po (also tried as .pot and .mo).

If I invoke xnec2c as LC_ALL=de_DE ./xnec2c then I know it gets the locale because decimal points become comma's instead of periods in floating point values, but the text is not being translated. I've tried setting LC_MESSAGES=de_DE as well but no change in the text language.

The _() macro is defined as:

#define _(String) dgettext (PACKAGE, String)

and autoconf has PACKAGE defined as "xnec2c" in configure.ac which does show up properly in config.h.

The console output uses vfprintf as follows, note the use of _(format):

vfprintf(stderr, _(format), args);

and I have verified that the formatted strings to be printed exist in the translated .pot file.

How do I go about troubleshooting this issue? I've read quite a bit of gettext documentation and I'm not sure what to try next.

(The 'gtk' tag is on here because we are using a translated .glade file, too, in case that is relevant.)

Here are some samples (mechanically-translated as de is not my native $LANG):

xnec2c.pot

#: src/callback_func.c:684
msgid "View Currents"
msgstr ""

#: src/callback_func.c:810
msgid "GNUplot files (*.gplot)"
msgstr ""

#: src/callbacks.c:88 src/callbacks.c:328 src/callbacks.c:2065
msgid "Really quit xnec2c?"
msgstr ""

/usr/share/locale/de_DE/LC_MESSAGES/xnec2c.po

msgid "View Currents"
msgstr "Ströme anzeigen"

msgid "GNUplot files (*.gplot)"
msgstr "GNUplot-Dateien (*.gplot)"

msgid "Really quit xnec2c?"
msgstr "Wirklich verlassen xnec2c?"
2 Answers

Near the start of the program you must call something like

  bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  textdomain(GETTEXT_PACKAGE);

where GETTEXT_PACKAGE and LOCALEDIR are macros that are usually defined by autoconf. (It seems you are using only PACKAGE instead of GETTEXT_PACKAGE, and LOCALEDIR is where the .mo files are stored.)

The translation file under /usr/share/... should be named xnec2c.mo, not .po. You mentioned having tried that already, but since you are not metioning msgfmt at all, did you perhaps simply rename the .po to .mo?

Renaming will not work, the file would be in the wrong format. The .po needs to be converted by using the command msgfmt -vco xnec2c.mo xnec2c.po.

(-v for verbose, -c for stricter syntax check, -o for output)

Related