Hi folks, I am trying to figure out why GNU gettext's behavior is not like strftime or printf when it comes to localization. I read the entire manual from A to Z but the examples are rather simple.
The task is to switch the locale in the application by user input to receive localized file output. Boiled down to a simple function: void localize(char *locale, struct tm *time) { printf("==============================================================\n"); printf("Passed locale: %s\n", locale); char *setlocale_out = setlocale(LC_ALL, locale); printf("Set locale: %s\n", setlocale_out); char buffer[80]; strftime(buffer, sizeof(buffer), "%c", time); printf("Localized time: %s\n", buffer); printf("Get rational, π: %f\n", PI); printf(_("Hello World!\n")); printf(_("Goodbye!\n")); } bindtextdomain() and text() are called before localize(char *, struct tm *). The entire function is called within loop with different locales. However, The strings do not change, though strtime/printf obey the locale, gettext() ignores the change. I have to call: setenv("LANG", locale, 1); bindtextdomain("my-i18n", LOCALEDIR); textdomain("my-i18n"); before using _(). While I understand that bindtextdomain() caches stuff in memory, why do I have to call setenv too? I have raised this some time ago on Stackoverflow [1] but was no given a qualified answer but for legacy support reasons. I am on FreeBSD 9.3-STABLE with gettext 0.19.8.1 Best regards, Michael Osipov [1] http://stackoverflow.com/q/40302497/696632