[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gettext] Irratic localization behavior of GNU gettext compared to s

From: Osipov, Michael
Subject: [bug-gettext] Irratic localization behavior of GNU gettext compared to strftime or printf
Date: Tue, 1 Nov 2016 12:36:42 +0000

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("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"));

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);

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

Best regards,

Michael Osipov

[1] http://stackoverflow.com/q/40302497/696632

reply via email to

[Prev in Thread] Current Thread [Next in Thread]