ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Language\ComponentTranslation\NativeGettext Class Reference

The process state native gettext (PHP extension "gettext") needs to serve the compiled catalogs of the migrated modules, and the one place that calls it. More...

+ Collaboration diagram for ILIAS\Language\ComponentTranslation\NativeGettext:

Static Public Member Functions

static isExtensionLoaded ()
 
static isThreadSafe ()
 Whether PHP is thread-safe (ZTS): the settings of activate() then apply to every thread and are not taken back. More...
 
static useThreadSafeForTests (?bool $thread_safe)
 Makes isThreadSafe() return $thread_safe (null: PHP_ZTS again) - for tests only. More...
 
static usesSystemLocale ()
 macOS/BSD: activate() uses a SYSTEM_LOCALES entry, their C library ignores LOCPATH. More...
 
static useSystemLocaleForTests (?bool $system_locale)
 Makes usesSystemLocale() return $system_locale (null: by PHP_OS_FAMILY again) - for tests only. More...
 
static activate (string $locale_directory)
 Sets LANGUAGE and, if LC_MESSAGES holds no real locale, the locale LOCALE_NAME of $locale_directory (or, see usesSystemLocale(), a system locale) for it; if it fails, getProblem() tells why. More...
 
static isActive ()
 Whether activate() succeeded and its settings are still in place (other code, e.g. More...
 
static reactivateIfLost ()
 Activates the locale again if it was activated before and the settings changed since. More...
 
static restore ()
 Takes LANGUAGE, LC_MESSAGES (if activate() set it) and LC_ALL back to the state before the first activate(); settings changed by other code since stay. More...
 
static getProblem ()
 
static bind (string $domain, string $directory)
 Binds $domain to $directory with the codeset UTF-8. More...
 
static isLoaded (string $domain)
 Whether the catalog of the bound $domain is readable: its header (the translation of the empty message id) is not empty. More...
 
static translate (string $domain, string $message_id)
 The translation of $message_id in $domain, or $message_id itself if there is none (as the C library answers), also for an empty or too long $message_id. More...
 
static translatePlural (string $domain, string $message_id, int $n)
 The form of the plural message $message_id the "Plural-Forms" rule of the catalog selects for $n (a negative $n counts as its absolute value), or $message_id itself if there is none. More...
 
static resetForTests ()
 Forgets the activation (without taking the settings back) - for tests only. More...
 

Data Fields

const string LOCALE_NAME = 'ilias_messages'
 
const array SYSTEM_LOCALES = ['en_US.UTF-8', 'en_US.utf8']
 LC_MESSAGES candidates where the system locale is used, see usesSystemLocale(). More...
 
const string CATALOG_LANGUAGE = 'messages'
 The value of LANGUAGE: the directory below a bound directory the catalogs are looked up in. More...
 
const string CATALOG_DIRECTORY = self::CATALOG_LANGUAGE . '/LC_MESSAGES'
 

Static Private Member Functions

static activateSystemLocale (string $locale_directory)
 
static keptLocale ()
 A real LC_MESSAGES locale stays, so ICU & Co. More...
 
static processState ()
 
static activated (string $locale_directory, string $locale, bool $messages_set)
 
static canLookUp (string $message_id)
 

Private Attributes

const array SYSTEM_LOCALE_OS_FAMILIES = ['Darwin', 'BSD']
 
const string CODESET = 'UTF-8'
 
const int MAX_MESSAGE_LENGTH = 4096
 Longer message ids are refused by PHP (ValueError), so they are never found. More...
 

Static Private Attributes

static string $locale_directory = null
 
static string $active_locale = null
 What setlocale() returned in the last successful activate(). More...
 
static array $previous = null
 
static bool $thread_safe_for_tests = null
 
static bool $system_locale_for_tests = null
 
static string $problem = null
 
static bool $messages_set = false
 

Detailed Description

The process state native gettext (PHP extension "gettext") needs to serve the compiled catalogs of the migrated modules, and the one place that calls it.

Native gettext only translates while LC_MESSAGES is not "C"/"POSIX" and finds a catalog as <bound directory>/<language>/LC_MESSAGES/<domain>.mo. ILIAS does not depend on the locale's language, so a real locale in LC_MESSAGES (e.g. of ilInitialisation::initLocale()) stays. Only for "C"/"POSIX"/"C.<codeset>":

  • glibc: the build ships its own locale (a copy of "C.utf8", see ShippedTranslationsBuild) named LOCALE_NAME; activate() loads it via LOCPATH and removes LOCPATH again right away (while it is set, setlocale() finds no system locale);
  • macOS/BSD (see usesSystemLocale()): the C library ignores LOCPATH, gettext comes from GNU libintl, so activate() sets the first existing of SYSTEM_LOCALES for LC_MESSAGES and the environment variable LC_ALL (GNU libintl ignores LANGUAGE for "C.<codeset>");
  • LANGUAGE is CATALOG_LANGUAGE, so "<language>" is always "messages"; the language of a catalog is part of its domain ("<module>.<lang>", see MigratedLanguageFilePaths), as the C library caches per process and a later LANGUAGE change would not reliably switch catalogs;
  • every domain is bound with codeset UTF-8, so LC_CTYPE never converts a value.

Both settings are process-wide. PHP takes them back at the end of every request (putenv() variables, setlocale() reset to "C"), so no shutdown function is needed (it would stop later shutdown functions from translating). In a thread-safe (ZTS) PHP the end of another thread's request can take them back mid-request: isActive() checks, reactivateIfLost() activates again (the administration shows a hint, see isThreadSafe()). Child processes inherit LANGUAGE=messages, which is harmless, and on macOS/BSD LC_ALL=<active locale> (a kept one too, e.g. the locale of the administration), which overrides the locale of the environment for them.

The C library never reloads a catalog file it has read once (also not a replaced one), so every new state (a build, an overlay revision) gets a directory of its own, and binding the domain loads it.

Definition at line 52 of file NativeGettext.php.

Member Function Documentation

◆ activate()

static ILIAS\Language\ComponentTranslation\NativeGettext::activate ( string  $locale_directory)
static

Sets LANGUAGE and, if LC_MESSAGES holds no real locale, the locale LOCALE_NAME of $locale_directory (or, see usesSystemLocale(), a system locale) for it; if it fails, getProblem() tells why.

Definition at line 136 of file NativeGettext.php.

136 : bool
137 {
138 if (!self::isExtensionLoaded()) {
139 self::$problem = 'the PHP extension "gettext" is not loaded in this PHP (the web server needs it like the CLI that ran the build)';
140 return false;
141 }
142 if (self::$locale_directory === $locale_directory && self::isActive()) {
143 return true;
144 }
145 if (self::usesSystemLocale()) {
147 }
148 // also checked when a real locale stays: a build without its locale is broken
149 if (!is_dir($locale_directory . '/' . self::LOCALE_NAME)) {
150 self::$problem = sprintf('the locale "%s" is missing in "%s"', self::LOCALE_NAME, $locale_directory);
151 return false;
152 }
153
154 self::$previous ??= self::processState();
155 $kept = self::keptLocale();
156 if ($kept !== null) {
157 return self::activated($locale_directory, $kept, false);
158 }
159 $locpath = getenv('LOCPATH');
160 putenv('LOCPATH=' . $locale_directory);
161 $locale = setlocale(LC_MESSAGES, self::LOCALE_NAME);
162 // as long as LOCPATH is set, setlocale() finds no locale of the system (e.g. for LC_TIME)
163 putenv($locpath === false ? 'LOCPATH' : 'LOCPATH=' . $locpath);
164 if ($locale !== self::LOCALE_NAME) {
165 self::$problem = sprintf('the locale "%s" of "%s" cannot be activated', self::LOCALE_NAME, $locale_directory);
166 return false;
167 }
168
169 return self::activated($locale_directory, $locale, true);
170 }
static activateSystemLocale(string $locale_directory)
static keptLocale()
A real LC_MESSAGES locale stays, so ICU & Co.
static activated(string $locale_directory, string $locale, bool $messages_set)

References ILIAS\Language\ComponentTranslation\NativeGettext\$locale_directory, ILIAS\Language\ComponentTranslation\NativeGettext\activated(), ILIAS\Language\ComponentTranslation\NativeGettext\activateSystemLocale(), ILIAS\Language\ComponentTranslation\NativeGettext\keptLocale(), and ILIAS\Language\ComponentTranslation\NativeGettext\processState().

Referenced by ILIAS\Language\ComponentTranslation\NativeGettextTest\activateBuild(), ILIAS\Language\ComponentTranslation\NativeGettextTest\activateSystemLocale(), ILIAS\Language\ComponentTranslation\NativeGettext\reactivateIfLost(), ILIAS\Language\ComponentTranslation\TranslationGettextRepository\state(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateFailsWithAProblemAndLeavesTheProcessAsItWas(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateStillFailsWithoutLocaleDirectoryWhenARealLocaleStays(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreAfterARepeatedActivationGivesBackLcAllFromBeforeTheFirstOne(), and ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchTranslatesWithoutLocaleDirectoryAndLeavesLocpathAlone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ activated()

static ILIAS\Language\ComponentTranslation\NativeGettext::activated ( string  $locale_directory,
string  $locale,
bool  $messages_set 
)
staticprivate

Definition at line 217 of file NativeGettext.php.

217 : bool
218 {
219 putenv('LANGUAGE=' . self::CATALOG_LANGUAGE);
220 self::$locale_directory = $locale_directory;
221 self::$active_locale = $locale;
222 self::$messages_set = $messages_set;
223 self::$problem = null;
224
225 return true;
226 }

References ILIAS\Language\ComponentTranslation\NativeGettext\$locale_directory, and ILIAS\Language\ComponentTranslation\NativeGettext\$messages_set.

Referenced by ILIAS\Language\ComponentTranslation\NativeGettext\activate(), and ILIAS\Language\ComponentTranslation\NativeGettext\activateSystemLocale().

+ Here is the caller graph for this function:

◆ activateSystemLocale()

static ILIAS\Language\ComponentTranslation\NativeGettext::activateSystemLocale ( string  $locale_directory)
staticprivate

Definition at line 172 of file NativeGettext.php.

172 : bool
173 {
174 self::$previous ??= self::processState();
175 $kept = self::keptLocale();
176 $locale = $kept ?? setlocale(LC_MESSAGES, self::SYSTEM_LOCALES);
177 if ($locale === false) {
178 self::$problem = sprintf(
179 'none of the system locales %s exists for LC_MESSAGES (needed on %s, where native gettext cannot use the locale of the build)',
180 implode(', ', self::SYSTEM_LOCALES),
181 PHP_OS_FAMILY
182 );
183 return false;
184 }
185 // GNU libintl on macOS reads the locale of the environment before setlocale()'s, and "C" there ignores LANGUAGE
186 putenv('LC_ALL=' . $locale);
187
188 return self::activated($locale_directory, $locale, $kept === null);
189 }

References ILIAS\Language\ComponentTranslation\NativeGettext\$locale_directory, ILIAS\Language\ComponentTranslation\NativeGettext\activated(), ILIAS\Language\ComponentTranslation\NativeGettext\keptLocale(), and ILIAS\Language\ComponentTranslation\NativeGettext\processState().

Referenced by ILIAS\Language\ComponentTranslation\NativeGettext\activate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bind()

static ILIAS\Language\ComponentTranslation\NativeGettext::bind ( string  $domain,
string  $directory 
)
static

◆ canLookUp()

static ILIAS\Language\ComponentTranslation\NativeGettext::canLookUp ( string  $message_id)
staticprivate

Definition at line 331 of file NativeGettext.php.

331 : bool
332 {
333 return $message_id !== '' && strlen($message_id) <= self::MAX_MESSAGE_LENGTH && self::isExtensionLoaded();
334 }

References ILIAS\Language\ComponentTranslation\NativeGettext\isExtensionLoaded().

+ Here is the call graph for this function:

◆ getProblem()

◆ isActive()

static ILIAS\Language\ComponentTranslation\NativeGettext::isActive ( )
static

Whether activate() succeeded and its settings are still in place (other code, e.g.

ilInitialisation::initLocale() with setlocale(LC_ALL, …), may have changed LC_MESSAGES since).

Definition at line 232 of file NativeGettext.php.

232 : bool
233 {
234 return self::$locale_directory !== null
235 && setlocale(LC_MESSAGES, '0') === self::$active_locale
236 && getenv('LANGUAGE') === self::CATALOG_LANGUAGE
237 && (!self::usesSystemLocale() || getenv('LC_ALL') === self::$active_locale);
238 }
static usesSystemLocale()
macOS/BSD: activate() uses a SYSTEM_LOCALES entry, their C library ignores LOCPATH.
static string $active_locale
What setlocale() returned in the last successful activate().

References ILIAS\Language\ComponentTranslation\NativeGettext\$active_locale, and ILIAS\Language\ComponentTranslation\NativeGettext\usesSystemLocale().

Referenced by ILIAS\Language\ComponentTranslation\TranslationGettextRepository\getPluralText(), ILIAS\Language\ComponentTranslation\TranslationGettextRepository\lookup(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateFailsWithAProblemAndLeavesTheProcessAsItWas(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateKeepsARealLocaleAndRestoreLeavesItWhileTakingLanguageBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateServesTheBuildAndRestoreGivesTheProcessStateBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateStillFailsWithoutLocaleDirectoryWhenARealLocaleStays(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testAfterRestoreReactivateIfLostActivatesTheLocaleAgain(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testGlibcBranchNeverTouchesLcAll(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostFailsWithAProblemWhenTheLocaleIsGone(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostKeepsALocaleOtherCodeSetForEverything(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsAForeignResetInAThreadSafePhpToo(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsWhatOtherCodeChanged(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsWhatOtherCodeChangedInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreChangesNothingInAThreadSafePhp(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreChangesNothingInAThreadSafePhpInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchKeepsARealLocaleSetsLcAllToItAndRestoreGivesLcAllBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchSetsLcAllToTheActiveLocaleAndRestoreGivesItBackExactly(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchTranslatesWithoutLocaleDirectoryAndLeavesLocpathAlone(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleIsOnlyActiveAfterActivateAndRestoreGivesTheProcessStateBack(), and ILIAS\Language\ComponentTranslation\NativeGettextTest\testTheOwnLocaleIsNeverTakenForARealOneAfterLanguageWasLost().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isExtensionLoaded()

static ILIAS\Language\ComponentTranslation\NativeGettext::isExtensionLoaded ( )
static

◆ isLoaded()

static ILIAS\Language\ComponentTranslation\NativeGettext::isLoaded ( string  $domain)
static

Whether the catalog of the bound $domain is readable: its header (the translation of the empty message id) is not empty.

Definition at line 299 of file NativeGettext.php.

299 : bool
300 {
301 return self::isExtensionLoaded() && dgettext($domain, '') !== '';
302 }

References ILIAS\Language\ComponentTranslation\NativeGettext\isExtensionLoaded().

Referenced by ILIAS\Language\ComponentTranslation\TranslationGettextRepository\state(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testIsLoadedTellsAReadableCatalogOfOurOwnByItsHeader(), and ILIAS\Language\ComponentTranslation\TranslationGettextRepository\withOverlay().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isThreadSafe()

static ILIAS\Language\ComponentTranslation\NativeGettext::isThreadSafe ( )
static

Whether PHP is thread-safe (ZTS): the settings of activate() then apply to every thread and are not taken back.

Definition at line 101 of file NativeGettext.php.

101 : bool
102 {
103 return self::$thread_safe_for_tests ?? (bool) PHP_ZTS;
104 }

Referenced by ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreChangesNothingInAThreadSafePhp().

+ Here is the caller graph for this function:

◆ keptLocale()

static ILIAS\Language\ComponentTranslation\NativeGettext::keptLocale ( )
staticprivate

A real LC_MESSAGES locale stays, so ICU & Co.

keep seeing it (e.g. the one of ilInitialisation::initLocale()).

Definition at line 192 of file NativeGettext.php.

192 : ?string
193 {
194 $locale = setlocale(LC_MESSAGES, '0');
195 if (
196 $locale === false
197 || $locale === 'C'
198 || $locale === 'POSIX'
199 || str_starts_with($locale, 'C.')
200 || $locale === self::LOCALE_NAME
201 || (self::$messages_set && $locale === self::$active_locale)
202 ) {
203 return null;
204 }
205
206 return $locale;
207 }

Referenced by ILIAS\Language\ComponentTranslation\NativeGettext\activate(), and ILIAS\Language\ComponentTranslation\NativeGettext\activateSystemLocale().

+ Here is the caller graph for this function:

◆ processState()

static ILIAS\Language\ComponentTranslation\NativeGettext::processState ( )
staticprivate
Returns
array{language: string|false, messages: string|false, all: string|false}

Definition at line 212 of file NativeGettext.php.

212 : array
213 {
214 return ['language' => getenv('LANGUAGE'), 'messages' => setlocale(LC_MESSAGES, '0'), 'all' => getenv('LC_ALL')];
215 }

Referenced by ILIAS\Language\ComponentTranslation\NativeGettext\activate(), and ILIAS\Language\ComponentTranslation\NativeGettext\activateSystemLocale().

+ Here is the caller graph for this function:

◆ reactivateIfLost()

static ILIAS\Language\ComponentTranslation\NativeGettext::reactivateIfLost ( )
static

Activates the locale again if it was activated before and the settings changed since.

Returns
bool whether it had to be (and could be) activated again - a lookup that found nothing is worth repeating then

Definition at line 246 of file NativeGettext.php.

246 : bool
247 {
248 if (self::$locale_directory === null || self::isActive()) {
249 return false;
250 }
251
252 return self::activate(self::$locale_directory);
253 }
static activate(string $locale_directory)
Sets LANGUAGE and, if LC_MESSAGES holds no real locale, the locale LOCALE_NAME of $locale_directory (...

References ILIAS\Language\ComponentTranslation\NativeGettext\activate().

Referenced by ILIAS\Language\ComponentTranslation\TranslationGettextRepository\getPluralText(), ILIAS\Language\ComponentTranslation\TranslationGettextRepository\lookup(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testAfterRestoreReactivateIfLostActivatesTheLocaleAgain(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostDoesNothingWithoutAnActivationOrWhileActive(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostFailsWithAProblemWhenTheLocaleIsGone(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostKeepsALocaleOtherCodeSetForEverything(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsAForeignResetInAThreadSafePhpToo(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsWhatOtherCodeChanged(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsWhatOtherCodeChangedInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreAfterARepeatedActivationGivesBackLcAllFromBeforeTheFirstOne(), and ILIAS\Language\ComponentTranslation\NativeGettextTest\testTheOwnLocaleIsNeverTakenForARealOneAfterLanguageWasLost().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetForTests()

static ILIAS\Language\ComponentTranslation\NativeGettext::resetForTests ( )
static

Forgets the activation (without taking the settings back) - for tests only.

Definition at line 341 of file NativeGettext.php.

341 : void
342 {
343 self::$thread_safe_for_tests = null;
345 self::$system_locale_for_tests = null;
346 self::$locale_directory = null;
347 self::$active_locale = null;
348 self::$messages_set = false;
349 self::$previous = null;
350 self::$problem = null;
351 }
static restore()
Takes LANGUAGE, LC_MESSAGES (if activate() set it) and LC_ALL back to the state before the first acti...

References ILIAS\Language\ComponentTranslation\NativeGettext\restore().

Referenced by ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\buildKind(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\buildWithSystemLocale(), ILIAS\Language\ComponentTranslation\NativeGettextTest\tearDown(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testABuildNativeGettextCannotServeLeavesCurrentAndThePreviousBuildAsTheyAreAndNoRemnants(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testABuildRemovesLeftoversOfItsOwnLocaleKindOnly(), ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\testASystemLocaleBuildOnAnotherPlatformServesNothingAndTheProblemNamesTheCause(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testBuildsOfTheOtherLocaleKindAndTheirPointerSurviveTheCleanup(), ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\testEachLocaleKindServesTheBuildOfItsOwnPointer(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostDoesNothingWithoutAnActivationOrWhileActive(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testSystemLocaleBuildShipsNoLocaleIsReusedAndDiffersFromTheGlibcBuild(), and ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\useRealLocaleForMessages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ restore()

static ILIAS\Language\ComponentTranslation\NativeGettext::restore ( )
static

Takes LANGUAGE, LC_MESSAGES (if activate() set it) and LC_ALL back to the state before the first activate(); settings changed by other code since stay.

Only for long-running processes (e.g. Setup's build after its check), a web request needs no call. No-op in a thread-safe PHP, where other threads may use them. The activated directory is kept, so reactivateIfLost() can activate it again.

Definition at line 261 of file NativeGettext.php.

261 : void
262 {
263 if (self::$previous === null || self::isThreadSafe()) {
264 return;
265 }
266 if (self::$messages_set && self::$previous['messages'] !== false && setlocale(LC_MESSAGES, '0') === self::$active_locale) {
267 setlocale(LC_MESSAGES, self::$previous['messages']);
268 }
269 if (getenv('LANGUAGE') === self::CATALOG_LANGUAGE) {
270 putenv(self::$previous['language'] === false ? 'LANGUAGE' : 'LANGUAGE=' . self::$previous['language']);
271 }
272 if (self::usesSystemLocale() && getenv('LC_ALL') === self::$active_locale) {
273 putenv(self::$previous['all'] === false ? 'LC_ALL' : 'LC_ALL=' . self::$previous['all']);
274 }
275 self::$previous = null;
276 }

Referenced by ILIAS\Language\Setup\ShippedLanguageFilesCompiledObjective\achieve(), ILIAS\Language\ComponentTranslation\NativeGettext\resetForTests(), ILIAS\Language\ComponentTranslation\NativeGettextTest\setUp(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateKeepsARealLocaleAndRestoreLeavesItWhileTakingLanguageBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateServesTheBuildAndRestoreGivesTheProcessStateBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testAfterRestoreReactivateIfLostActivatesTheLocaleAgain(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testALocaleOfTheCFamilyIsNotRealSoTheOwnLocaleIsActivatedAndTakenBackAgain(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testGlibcBranchNeverTouchesLcAll(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostKeepsALocaleOtherCodeSetForEverything(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsAForeignResetInAThreadSafePhpToo(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreAfterARepeatedActivationGivesBackLcAllFromBeforeTheFirstOne(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreChangesNothingInAThreadSafePhp(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreChangesNothingInAThreadSafePhpInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreLeavesALcAllOtherCodeChangedSinceAsItIsInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreLeavesASettingOtherCodeChangedSinceAsItIs(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreWithoutActivationChangesNothing(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchKeepsARealLocaleSetsLcAllToItAndRestoreGivesLcAllBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchSetsLcAllToTheActiveLocaleAndRestoreGivesItBackExactly(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleIsOnlyActiveAfterActivateAndRestoreGivesTheProcessStateBack(), and ILIAS\Language\ComponentTranslation\NativeGettextTest\testTheOwnLocaleIsNeverTakenForARealOneAfterLanguageWasLost().

+ Here is the caller graph for this function:

◆ translate()

static ILIAS\Language\ComponentTranslation\NativeGettext::translate ( string  $domain,
string  $message_id 
)
static

The translation of $message_id in $domain, or $message_id itself if there is none (as the C library answers), also for an empty or too long $message_id.

Definition at line 308 of file NativeGettext.php.

308 : string
309 {
310 if (!self::canLookUp($message_id)) {
311 return $message_id;
312 }
313
314 return dgettext($domain, $message_id);
315 }

Referenced by ILIAS\Language\ComponentTranslation\TranslationGettextRepository\lookup(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateKeepsARealLocaleAndRestoreLeavesItWhileTakingLanguageBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testActivateServesTheBuildAndRestoreGivesTheProcessStateBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testAfterRestoreReactivateIfLostActivatesTheLocaleAgain(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testALocaleOfTheCFamilyIsNotRealSoTheOwnLocaleIsActivatedAndTakenBackAgain(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostKeepsALocaleOtherCodeSetForEverything(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsAForeignResetInAThreadSafePhpToo(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsWhatOtherCodeChanged(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsWhatOtherCodeChangedInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchKeepsARealLocaleSetsLcAllToItAndRestoreGivesLcAllBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchSetsLcAllToTheActiveLocaleAndRestoreGivesItBackExactly(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchTranslatesWithoutLocaleDirectoryAndLeavesLocpathAlone(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testTheIcuDefaultLocaleStaysTheOneOfTheAdministrator(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testTheOwnLocaleIsNeverTakenForARealOneAfterLanguageWasLost(), and ILIAS\Language\ComponentTranslation\NativeGettextTest\testTranslateAnswersTheMessageIdItself().

+ Here is the caller graph for this function:

◆ translatePlural()

static ILIAS\Language\ComponentTranslation\NativeGettext::translatePlural ( string  $domain,
string  $message_id,
int  $n 
)
static

The form of the plural message $message_id the "Plural-Forms" rule of the catalog selects for $n (a negative $n counts as its absolute value), or $message_id itself if there is none.

Definition at line 321 of file NativeGettext.php.

321 : string
322 {
323 if (!self::canLookUp($message_id)) {
324 return $message_id;
325 }
326 $n = $n === PHP_INT_MIN ? PHP_INT_MAX : abs($n);
327
328 return dngettext($domain, $message_id, $message_id, $n);
329 }

Referenced by ILIAS\Language\ComponentTranslation\TranslationGettextRepository\getPluralText(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testTranslateAnswersTheMessageIdItself(), and ILIAS\Language\ComponentTranslation\NativeGettextTest\testTranslatePluralSelectsTheFormOfTheAbsoluteQuantity().

+ Here is the caller graph for this function:

◆ usesSystemLocale()

static ILIAS\Language\ComponentTranslation\NativeGettext::usesSystemLocale ( )
static

◆ useSystemLocaleForTests()

static ILIAS\Language\ComponentTranslation\NativeGettext::useSystemLocaleForTests ( ?bool  $system_locale)
static

Makes usesSystemLocale() return $system_locale (null: by PHP_OS_FAMILY again) - for tests only.

Definition at line 127 of file NativeGettext.php.

127 : void
128 {
129 self::$system_locale_for_tests = $system_locale;
130 }

Referenced by ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\buildKind(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\buildWithSystemLocale(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testABuildNativeGettextCannotServeLeavesCurrentAndThePreviousBuildAsTheyAreAndNoRemnants(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testABuildRemovesLeftoversOfItsOwnLocaleKindOnly(), ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\testANewerBuildOfTheOtherLocaleKindIsHintedAtOnlyForOtherShippedFiles(), ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\testASystemLocaleBuildOnAnotherPlatformServesNothingAndTheProblemNamesTheCause(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testBuildsOfTheOtherLocaleKindAndTheirPointerSurviveTheCleanup(), ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\testEachLocaleKindServesTheBuildOfItsOwnPointer(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testMissingLocaleOfTheCLibraryAbortsBeforeAnythingIsWritten(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testPlatformProblemTellsASystemLocaleBuildOnlyWhereTheShippedLocaleIsNeeded(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostKeepsALocaleOtherCodeSetForEverything(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testReactivateIfLostRepairsWhatOtherCodeChangedInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreAfterARepeatedActivationGivesBackLcAllFromBeforeTheFirstOne(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreChangesNothingInAThreadSafePhpInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testRestoreLeavesALcAllOtherCodeChangedSinceAsItIsInTheSystemLocaleBranch(), ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\testSwitchingTheLocaleKindReadsTheOtherPointerWithoutAReset(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchKeepsARealLocaleSetsLcAllToItAndRestoreGivesLcAllBack(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchSetsLcAllToTheActiveLocaleAndRestoreGivesItBackExactly(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleBranchTranslatesWithoutLocaleDirectoryAndLeavesLocpathAlone(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testSystemLocaleBuildShipsNoLocaleIsReusedAndDiffersFromTheGlibcBuild(), ILIAS\Language\ComponentTranslation\NativeGettextTest\testSystemLocaleIsOnlyActiveAfterActivateAndRestoreGivesTheProcessStateBack(), ILIAS\Language\ComponentTranslation\MigratedTranslationsTest\testWithoutAnOwnPointerTheMissingBuildIsFatalAndNamesTheBuildOfTheOtherKind(), and ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\useRealLocaleForMessages().

+ Here is the caller graph for this function:

◆ useThreadSafeForTests()

static ILIAS\Language\ComponentTranslation\NativeGettext::useThreadSafeForTests ( ?bool  $thread_safe)
static

Field Documentation

◆ $active_locale

string ILIAS\Language\ComponentTranslation\NativeGettext::$active_locale = null
staticprivate

What setlocale() returned in the last successful activate().

Definition at line 74 of file NativeGettext.php.

Referenced by ILIAS\Language\ComponentTranslation\NativeGettext\isActive().

◆ $locale_directory

string ILIAS\Language\ComponentTranslation\NativeGettext::$locale_directory = null
staticprivate

◆ $messages_set

bool ILIAS\Language\ComponentTranslation\NativeGettext::$messages_set = false
staticprivate

◆ $previous

array ILIAS\Language\ComponentTranslation\NativeGettext::$previous = null
staticprivate

Definition at line 82 of file NativeGettext.php.

◆ $problem

string ILIAS\Language\ComponentTranslation\NativeGettext::$problem = null
staticprivate

◆ $system_locale_for_tests

bool ILIAS\Language\ComponentTranslation\NativeGettext::$system_locale_for_tests = null
staticprivate

Definition at line 86 of file NativeGettext.php.

◆ $thread_safe_for_tests

bool ILIAS\Language\ComponentTranslation\NativeGettext::$thread_safe_for_tests = null
staticprivate

Definition at line 84 of file NativeGettext.php.

◆ CATALOG_DIRECTORY

◆ CATALOG_LANGUAGE

◆ CODESET

const string ILIAS\Language\ComponentTranslation\NativeGettext::CODESET = 'UTF-8'
private

Definition at line 66 of file NativeGettext.php.

◆ LOCALE_NAME

◆ MAX_MESSAGE_LENGTH

const int ILIAS\Language\ComponentTranslation\NativeGettext::MAX_MESSAGE_LENGTH = 4096
private

Longer message ids are refused by PHP (ValueError), so they are never found.

Definition at line 69 of file NativeGettext.php.

◆ SYSTEM_LOCALE_OS_FAMILIES

const array ILIAS\Language\ComponentTranslation\NativeGettext::SYSTEM_LOCALE_OS_FAMILIES = ['Darwin', 'BSD']
private

Definition at line 59 of file NativeGettext.php.

◆ SYSTEM_LOCALES


The documentation for this class was generated from the following file: