community/php8?: setlocale() without function
When using PHP on Alpine Linux the setlocale()
function does not change the locale as it should.
Changes to the LANG
environment variable are sometimes respected.
I generated a minimal example: php-gettext-musl.tar
When I run the test.php
script I get the following output:
$ env -i php81 test.php
C
en_GB: Welcome
de_CH: Willkommen
en_GB: Willkommen
When I run the same script on a glibc-based system or Gentoo/musl I get the expected output:
$ env -i php8.1 test.php
C
en_GB: Welcome
de_CH: Willkommen
en_GB: Welcome
If I comment line 6 (putenv("LANG={$new}");
) I get the following output on Alpine Linux:
$ sed -i~ '/putenv(/s#^#// #' test.php
$ env -i php81 test.php
C
en_GB: Welcome
de_CH: Welcome
en_GB: Welcome
For completeness I translated the example code to C: test.c
When I install the musl-libintl
package and compile the code I get the expected output:
$ apk add gcc musl-dev musl-libintl
$ gcc -o test-musl test.c
$ env -i ./test-musl
C
en_GB: Welcome
de_CH: Willkommen
en_GB: Welcome
When I install gettext
however and compile the code I get the same behaviour as in PHP:
$ apk add gcc musl-dev gettext-dev
$ gcc -o test-gnu test.c -lintl
$ env -i ./test-gnu
C
en_GB: Welcome
de_CH: Willkommen
en_GB: Willkommen