WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Multilanguage app compiles but translation are ignored  (Read 5922 times)

Offline christianix

  • Newbie
  • *
  • Posts: 9
Multilanguage app compiles but translation are ignored
« on: August 18, 2016, 09:38:51 AM »
Hi,

I'm building a small program with internationalization support under Ubuntu 14.04 and there it's behaving as expected. I can also build the same tool on TC 7.x without problems. But on TC it's just not looking up the translations.

The source file is attached and can be build with the following Makefile:
Code: [Select]
CFLAGS=-W -Wall -O0 -g -std=c99

PROGS=\
  test-gettext

all: ${PROGS}

%: %.c
$(CC) $(CFLAGS) -o $@ $<

clean:
$(RM) ${PROGS}

The first two steps for translation I did on Ubuntu:
  • xgettext -kN_ -d test-gettext -o test-gettext.pot test-gettext.c
  • msginit --no-translator -l de -o test-gettext-de.po -i test-gettext.pot

The binary translation file was created on TC (again):
  • mkdir -p share/locale/de/LC_MESSAGES
  • msgfmt -c -v -o share/locale/de/LC_MESSAGES/test-gettext.mo test-gettext-de.po

I'm using the latest TC 7.x with the following TCEs in onboot.lst:
Quote
gcc.tcz
gettext.tcz
mc.tcz
mc-locale.tcz
compiletc.tcz
strace.tcz
gettext-dev.tcz

When I compare the strace (-f -e trace=file) on Ubuntu and TC I see that on Ubuntu it opens the test-gettext.mo file. In TC I don't even see a try to open it.

Any ideas what I am missing?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Multilanguage app compiles but translation are ignored
« Reply #1 on: August 18, 2016, 01:18:06 PM »
Did you install a German locale first? (via getlocale.tcz)

Just setting LANG=de_DE without installing such wouldn't work. As TC is bare-bones, only the C locale is included by default.
The only barriers that can stop you are the ones you create yourself.

Offline christianix

  • Newbie
  • *
  • Posts: 9
Re: Multilanguage app compiles but translation are ignored
« Reply #2 on: August 18, 2016, 04:40:03 PM »
I'm not using translated system messages. I also called my locale de. I call my program like this:
Code: [Select]
> LANGUAGE="de" ./test-gettext
And on Ubuntu I see it opening share/locale/de/LC_MESSAGES/test-gettext.mo with strace. On TC I don't see even a try to open it. So I thing something is going wrong during the build process.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Multilanguage app compiles but translation are ignored
« Reply #3 on: August 19, 2016, 03:59:39 AM »
You must install a German locale for any app to use it, including yours. Installing one does not change the system's language, merely makes that locale available.
The only barriers that can stop you are the ones you create yourself.

Offline christianix

  • Newbie
  • *
  • Posts: 9
Re: Multilanguage app compiles but translation are ignored
« Reply #4 on: August 19, 2016, 08:17:38 AM »
I gave it a try. However, when running sudo getlocale.sh (with de_DE/UTF-8 selected) I get:

Quote
cannot open locale archive "/usr/lib/locale/locale-archive": Read-only file system

The script creates the archive mylocale.tcz and a corresponding entry in onboot.lst. However the archive contains only:

Quote
squashfs-root
squashfs-root/usr
squashfs-root/usr/lib
squashfs-root/usr/lib/locale
squashfs-root/usr/lib/locale/locale-archive

My test program now also tries to open some locale dependent files:

Quote
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/de/LC_IDENTIFICATION", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

But it's still not looking up the message archive (.mo) required. :-(

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14851
Re: Multilanguage app compiles but translation are ignored
« Reply #5 on: August 19, 2016, 08:47:50 AM »
If things work properly, /usr/lib/locale/locale-archive is a file of +/- 1.5mb.

Maybe you could delete /usr/lib/locale/locale-archive and try "sudo getlocale.sh" again?

Offline christianix

  • Newbie
  • *
  • Posts: 9
Re: Multilanguage app compiles but translation are ignored
« Reply #6 on: August 19, 2016, 10:24:36 AM »
I removed the mylocale.tcz as suggested (from onboot.lst and in optional), then recreated the locale package again - with only de_DE/UTF-8 locale. Now /usr/lib/locale/locale-archive is indeed something around 1.5 MB. I also recompiled my test program but behaviour is still the same.

Is there some global locale package I'm missing? Or an extra package for libc or gcc?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14851
Re: Multilanguage app compiles but translation are ignored
« Reply #7 on: August 19, 2016, 12:30:54 PM »
I presume you rebooted with mylocale "onboot" and the boot code analgous to "lang=en_US.UTF-8"?

If so, you could try the intltool, gcc_libs, glibc_add_lib, glibc_apps, glibc_gconv and glibc_i18n_locale extensions.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Multilanguage app compiles but translation are ignored
« Reply #8 on: August 19, 2016, 01:42:41 PM »
When using de_DE.utf8, you must use that string in LANG. Just trying to use "de" or "de_DE" does not match that one.

To check if your locale env vars are correct, run "locale".
The only barriers that can stop you are the ones you create yourself.

Offline christianix

  • Newbie
  • *
  • Posts: 9
Re: Multilanguage app compiles but translation are ignored
« Reply #9 on: August 21, 2016, 04:26:18 PM »
Ok, it's working now. Thanks to everybody!

The crucial point is described in this sentence of the man page:

Quote
In the "C" locale, ... , the gettext,  dgettext  and  dcgettext functions  return msgid.

Which means that the locale must be set to any locale supported by the system but must not be "C". Only then my translations are looked up - even tough I'm defining my own message catalogue and binding. This seems quite weird to me - as many things with the gettext functionality.