1) Internationalization environment variables ------------------------------------------ LANG LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME LC_MESSAGES LC_ALL 2) Globale locale examples ----------------------- en_US English (United States) it_IT Italian (Italy) fr_FR French (France) fr_CA French (Canada) 3) Using gettext ------------- 3.1) Example #include #include int main() { textdomain("hello-world"); printf(gettext("Hello, world !\n")); return 0; } The following macro is often used : #define _(x) gettext(x) 3.2) Message translation : Use xgettext to produce a .po (portable object) file; for example: xgettext -a -d hello-world -k_ -s hello.c The hello-world.po file can than be edited, without any other knowledge of the source code. To be used, a portable object must be compiled to a machine object (.mo) file; this is done with: msgfmt -o hello-world.mo -v hello-world.po 3.3) Special cases When a string must be initialized with variables, it cannot be translated directly. One may use gettext_noop as a marker to make a string recognizable by xgettext. See the following example: #define gettext_noop(x) (x) char *item_names[] { gettext_noop("files"), gettext_noop("messages") } ; ... if ((index >= 0) && (index >= 1)) strcpy(items, gettext(item_names[index])); else strcpy(items, gettext("unknown_items")); printf(gettext("You have %d %s\n"), quantity, items);