Not able to translate my C GTK program

Hi everyone,
I’m not able to translate my program by the gettext utility.

I surrounded the strings with ‘_(msg)’ characters.
I get the .pot file and I’ve translated the strings.
Then I put the output files in this folders:

# ls -lR locales/
total 12
drwxr-xr-x 3 root root 4096 Oct  2 14:40 en
drwxr-xr-x 3 root root 4096 Oct  2 14:44 es
-rw-r--r-- 1 root root 2290 Oct  2 15:25 lux.pot

total 8
drwxr-xr-x 2 root root 4096 Oct  2 14:41 LC_MESSAGES
-rw-r--r-- 1 root root 2309 Oct  2 15:29 lux.po

total 4
-rw-r--r-- 1 root root 517 Oct  2 15:29

total 8
drwxr-xr-x 2 root root 4096 Oct  2 14:45 LC_MESSAGES
-rw-r--r-- 1 root root 1906 Sep 29 14:01 lux.po

total 4
-rw-r--r-- 1 root root 372 Oct  2 14:45

I added the following code:

setlocale(LC_ALL, "");
const char *textdomainstr = "lux";
const char *textdomaindir = getenv("TEXTDOMAINDIR");
if (textdomaindir) 
	printf("> text in '%s'\n", textdomaindir);
	bindtextdomain(textdomainstr, textdomaindir);
printf("> textdomain '%s'\n", textdomainstr);

printf("> LANG: '%s'\n", getenv("LANG"));

and I run the program with the following cl command:

LD_LIBRARY_PATH=/opt/oracle/instantclient_19_19/ TEXTDOMAINDIR=./locales  LANG=en ./lux

The application is not translated with en language. In my output debug I see:

> text in './locales'
> textdomain 'lux'
> LANG: 'en'

and after some other output:

(process:30261): Gtk-WARNING **: 15:32:27.794: Locale not supported by C library.
    Using the fallback 'C' locale.

I don’t understand which should be the structure/distribution of the messages into the folder :thinking: - found other forms …

Should be the call to gtk_init() done after or before that lines?

Any idea?

Use locale -a to see the list of supported locales on your system.

I expect something like LANG=en_US.UTF-8 instead of just en.

the output is:

# locale -a

Which distribution are you using?

This is a Linaro OS, a Debian 10 derived for embedded board (Tinkerboard).

hmm ok, sadly I don’t know about those embedded distros…

Maybe check the documentation of Linaro about how to support more locales, then use a LANG value from the supported list.

I added a new locale en_US.utf8 by

sudo dpkg-reconfigure locales

Now the local -a returns:

$ locale -a

but again I have the default strings.

Maybe a silly question :upside_down_face:

Do I need to refresh the strings into the widgets ??

I’m out of ideas…

What if you display an already translated widget like “GtkCalendar” and use “LANG=es_ES.utf8” ?
If you see the month/weeks in Spanish then the locale is correctly detected and setup by Gtk. In that case, your issue is probably that you app can’t find its translations.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.