bug-gettext
[Top][All Lists]
Advanced

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

macOS 12 - cannot override LC_ALL=C setting from environment


From: Gavin Smith
Subject: macOS 12 - cannot override LC_ALL=C setting from environment
Date: Sat, 30 Nov 2024 20:43:20 +0000

Hello Bruno et al,

In the Texinfo project, we had reports of failures in the test suite on
certain platforms (macOS 13 and Cygwin64) which were due to strings not
being translated properly.

The problem appears to be due to a setting of LC_ALL=C in the environment.
The gettext manual documents that setting LC_ALL to "C" disables all
translations.  However, before getting the translations, we set LC_ALL
to a different value if at all possible.

I managed to replicate the issue with shell access to a macOS 13 system
(via the cfarm compile farm (https://portal.cfarm.net/).)

Output of uname -a:
Darwin cfarm104.cfarm.net 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 
20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64

I got it down to a short C program:

#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>

int
main (void)
{
  char *a = setlocale(LC_ALL, "en_US.UTF-8");
  printf("setlocale returned %s\n", a);
  setenv("LANG", "pt", 1);
  bindtextdomain("texinfo_document", "../../../build/tp/LocaleData");
  textdomain("texinfo_document");
  char *s = gettext("Special Form");
  printf("result %s\n", s);
}

I compile this with

cc -I/opt/homebrew/include -L/opt/homebrew/lib test.c  -lintl 

The directory given as the argument to bindtextdomain contains language
directories with .mo files in them, e.g. pt/LC_MESSAGES/texinfo_document.mo.

Then, running "./a.out" gives the translated string:

setlocale returned en_US.UTF-8
result Formulário especial

However, running "LC_ALL=C ./a.out" does not:

setlocale returned en_US.UTF-8
result Special Form

So even though we try to override LC_ALL by calling setlocale in the
program, nothing happens.

/opt/homebrew/include/libintl.h has "#define LIBINTL_VERSION 0x001605".

Note that we use LC_ALL=C when running the tests (of the texi2any program)
so that we get reproducible warning and error messages.  However we still
need translation of strings that are going into an output file, which
depends on the language of the document, not on the language of the user.

Any idea why this happens or how to fix it?

Thanks.



reply via email to

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