Skip to content

[FIX] Language: Keep a real LC_MESSAGES locale for native gettext - #12332

Merged
c-knof merged 2 commits into
ILIAS-eLearning:trunkfrom
kroepelin-projekte:fix/trunk/ck/language-gettext-global-state
Oct 30, 2026
Merged

c-knof merged 2 commits into
ILIAS-eLearning:trunkfrom
kroepelin-projekte:fix/trunk/ck/language-gettext-global-state

Conversation

@c-knof

@c-knof c-knof commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #12327, after a question by Michael Jansen about global state.

  • NativeGettext replaced LC_MESSAGES even where ilInitialisation::initLocale() had set a real locale (e.g. de_DE.UTF-8), so the ICU default locale could become "ilias__MESSAGES". It now sets LC_MESSAGES only for C, POSIX and C.<codeset> and otherwise sets just LANGUAGE (and LC_ALL in the environment on macOS/BSD). restore() only takes back what it set.
  • ShippedTranslationsBuild checks a build with its own locale, so a broken copy of the shipped locale is also refused when a real locale was active before.
  • Tests: a trait RestoresProcessState restores all locale categories, LANGUAGE, LC_ALL, LC_MESSAGES, LOCPATH, LANG and the static state after each test. Before, ShippedPoMergerTest and ShippedLanguageFilesCompiledObjectiveTest left LANGUAGE/LC_MESSAGES behind. Checked with a PHPUnit extension after every test: 0 leaks in 8 runs with random order.

Checked on macOS (Homebrew PHP 8.5, gettext 1.0) with GitHub Actions: lookups and setup build under 8 locale environments, an administrator locale before and after the first lookup with php -S and php-fpm, and the Language tests. Under php-fpm without a locale environment a plain dgettext() crashes the forked worker (SIGSEGV, see beyondcode/herd-community#1656), the lookups of ILIAS do not, as they set LC_ALL since #12327.

Without an administrator locale, a php-fpm worker whose first ICU call comes before a lookup keeps "ilias__MESSAGES" as ICU default locale (documented in the README). No code in the core uses the ICU default locale.

`NativeGettext` replaced LC_MESSAGES even where `ilInitialisation::initLocale()` had set a real locale, so e.g. the
ICU default locale could become "ilias__MESSAGES". It now sets LC_MESSAGES only for C, POSIX and C.<codeset>, and
`ShippedTranslationsBuild` checks a build with its own locale. The Language tests restore locale, environment and
static state after each test (`RestoresProcessState`).
@c-knof c-knof added bugfix php Pull requests that update Php code labels Oct 30, 2026
@c-knof
c-knof merged commit b51bc09 into ILIAS-eLearning:trunk Oct 30, 2026
5 checks passed
@c-knof
c-knof deleted the fix/trunk/ck/language-gettext-global-state branch October 30, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant