On Sat, Dec 21, 2024 at 06:59:01PM +0000, Gavin Smith wrote:
> On Mon, Dec 16, 2024 at 11:31:31PM +0100, Patrice Dumas wrote:
> > Hello,
> > 
> > I tested GNU Texinfo on Alpine Linux, which uses musl and not glibc in
> > cfarm94.cfarm.net.  Tests with translations of strings in output in C
> > fail, most probably because musl libintl does not use LANGUAGE to set
> > the locale.  In that case, setting the configure
> > --enable-xs-perl-libintl flag fixes the tests and the build.  Should
> > that situation be documented in the manual?
> 
> Can you point me to any documentation about the behavour of
> musl gettext and its treatment of LANGUAGE?

I did not find documentation, but I looked a bit at the code and tried
to use gdb to find where it was in the code.  But, mainly I used strace
and it showed the LANGUAGE was not honoured.

> Note I had to unset LC_ALL with "unsetenv", as LC_ALL takes priority
> over LANG and LC_MESSAGES (unlike the unsupported LANGUAGE).
> (Setting LC_ALL to "" in the environment had the same effect.)
> 
> Whereas at least 4 tests, including
> test_scripts/formatting_documentlanguage_cmdline.sh didn't pass
> under tp/tests (tp/t tests were disabled), now I was able to get
> all tests to pass by adding lines to tp/Texinfo/XS/main/translations.c:

I do not like the idea of resetting or unsetting LC_ALL, as when it is
reset, the specific locale categories informations are lost, but we
already reset LC_ALL, so we already have this issue.

> diff --git a/tp/Texinfo/XS/main/translations.c 
> b/tp/Texinfo/XS/main/translations.c
> index 4a904e1fff..0bcaf6d46f 100644
> --- a/tp/Texinfo/XS/main/translations.c
> +++ b/tp/Texinfo/XS/main/translations.c
> @@ -310,6 +310,20 @@ translate_string (const char *string, const char 
> *in_lang,
>                language_locales.text, string, strerror (errno));
>      }
>  
> +#ifndef _WIN32
> +  if (setenv ("LC_MESSAGES", language_locales.text, 1) != 0
> +          || unsetenv ("LC_ALL") != 0)
> +    {
> +      fprintf (stderr,
> +              "translate_string: setenv `%s' error for string `%s': %s\n",
> +              language_locales.text, string, strerror (errno));
> +    }
> +  else
> +    {
> +      char *cur = setlocale (LC_MESSAGES, "");
> +    }
> +#endif
> +
>    /* pgettext only works with string litterals, so use pgettext_expr */
>    if (translation_context)
>      translated_string = strdup (pgettext_expr (translation_context, string));
> 
> I then checked that this worked well on my own machine, which it did.
> 
> Then the call to switch_messages_locale is not actually needed as LC_MESSAGES
> is set.  This means we don't have to go looking for a working LC_ALL
> setting.
> 
> Any thoughts if we should adopt this approach for Alpine Linux and musl
> and even by default?

If the documentlanguage is fr_FR, we set LANGUAGE=fr_FR:fr.  I guess
that this would not work with LC_MESSAGES.  We could use LC_MESSAGES
on musl but still use LANGUAGE on other platforms for that feature?

-- 
Pat

Reply via email to