|
ILIAS
trunk Revision v13.0_alpha-62-g3b72d83f2e5
|
Builds what native gettext serves for the migrated modules (see TranslationGettextRepository) from every shipped .po of every contributed LanguageFileDirectory; run by Setup's build (ShippedLanguageFilesCompiledObjective) only, never by the web server (it does not write artifacts/; "merge" only writes the shipped .po, see ShippedPoMerger).
More...
Collaboration diagram for ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild:Public Member Functions | |
| __construct (private readonly LanguageFileDirectoryManager $language_file_directory_manager, private readonly string $ilias_absolute_path, private readonly ShippedTranslations $shipped_translations=new ShippedTranslations(), private readonly ?string $locale_source=null) | |
| run (callable $inform) | |
Static Public Member Functions | |
| static | readPointer (string $artifact_directory) |
The pointer of this PHP's locale kind in $artifact_directory, null if it is missing or not valid. More... | |
| static | readPointerOf (string $artifact_directory, bool $system_locale) |
| static | servesShippedPo (string $artifact_directory, string $module, string $lang_key, string $shipped_po) |
Whether the build of $artifact_directory serves exactly the shipped .po $shipped_po of $module for $lang_key (its content hash, see the manifest) - false without a build or after a change of the .po since (e.g. More... | |
| static | platformProblem (string $build_directory) |
| Why a build made with a system locale (macOS/BSD) cannot be activated by a PHP needing the shipped one. More... | |
Private Member Functions | |
| runLocked (string $artifact_directory, callable $inform) | |
| write (string $artifact_directory, string $build_directory, string $build_id, array $modules, ?string $locale_source, array $former_builds) | |
| Writes the build $build_id into a temporary directory and renames that to $build_directory. More... | |
| formerCatalog (string $artifact_directory, array $former_builds, string $module, string $lang_key) | |
| The catalog of $module/$lang_key in the first former build that has it intact and compiled the same way (see catalogCompatibility()). More... | |
| templateKeys (?string $template, string $module, array &$warnings) | |
The identifiers of $module in its template (.pot), [] if there is none or it cannot be read (reported). More... | |
| findCollisions (array $values_per_language) | |
| The identifiers with different values in several modules, per language. More... | |
| assertNativeGettextServes (string $build_directory, array $sample) | |
| Looks $sample up through native gettext in the build $build_directory. More... | |
| assertActivatedNativeGettextServes (string $build_directory, array $sample) | |
| findShippedFiles (callable $inform) | |
Every shipped .po of every contributed directory with a module prefix (the main lang/ directory has none and holds no .po), per module. More... | |
| buildId (array $source_parts, ?string $locale_source) | |
| sourceParts (array $modules) | |
| codeFingerprint () | |
| Over the code that determines the build, see FORMAT_VERSION. More... | |
| directoryFingerprint (string $directory) | |
| Over the content of every file below $directory - a locale copied from another version of the C library may not be loadable by the one in use. More... | |
| listFiles (string $directory) | |
| findLocaleSource () | |
| copyLocale (string $source, string $target, string $build_directory, array &$files) | |
| isIntact (string $build_directory, array $manifest) | |
| Whether every file of $manifest is in $build_directory as it was written - without fsync(), a crash can leave empty or truncated files behind. More... | |
| writePointer (string $artifact_directory, array $pointer) | |
| removeObsolete (string $artifact_directory, array $keep) | |
Removes everything of a former build of this locale kind except the builds $keep: other builds, temporary directories and files of aborted builds, and the former layout (<lang>/<module>.mo, index.json). More... | |
| holdsOnlyCatalogs (string $directory) | |
Whether $directory (of the former layout <lang>/<module>.mo) holds nothing but catalogs and temporary files of them. More... | |
| removeTree (string $artifact_directory, string $path) | |
| Removes $path recursively - only below $artifact_directory, and without following a symbolic link (a link itself is removed). More... | |
| writeFile (string $file, string $content) | |
| ensureDirectory (string $directory) | |
| relativePath (string $file) | |
Static Private Member Functions | |
| static | catalogCompatibility () |
| Fingerprint of the compiling and cleaning code: formerCatalog() only takes over catalogs with the same one. More... | |
| static | classesFingerprint (array $classes) |
| static | readManifest (string $build_directory) |
| static | hashes (mixed $value) |
| static | stringList (mixed $value) |
Private Attributes | |
| const int | FORMAT_VERSION = 4 |
| Raise to rebuild when the output changes for a reason the fingerprint of the involved classes does not capture, e.g. More... | |
| const array | CATALOG_CLASSES |
| The classes that determine the bytes of a compiled catalog (MigratedLanguageFileSync: moduleEntries()). More... | |
| const string | MANIFEST_FILE = 'manifest.json' |
| const string | MARKUP_WARNING = 'Markup not allowed in a language value' |
| const string | LOCK_FILE = 'build.lock' |
| const array | LOCALE_SOURCES |
| Where the C library's "C.utf8" locale is looked for (Debian/Ubuntu, Fedora/RHEL, Arch, ...). More... | |
Static Private Attributes | |
| static array | $manifests = [] |
| static array | $system_locale_platforms = [] |
Builds what native gettext serves for the migrated modules (see TranslationGettextRepository) from every shipped .po of every contributed LanguageFileDirectory; run by Setup's build (ShippedLanguageFilesCompiledObjective) only, never by the web server (it does not write artifacts/; "merge" only writes the shipped .po, see ShippedPoMerger).
Requirement: on glibc the locale is copied from the C library of the build host and checked in that (CLI) process only. The web server must use the same C library (glibc with C.utf8) and have the PHP extension "gettext"; with separate CLI/web images or a musl based system (which ignores LOCPATH) the runtime serves -identifier- and reports why (see MigratedTranslations::getProblem()). macOS/BSD ship no locale.
Layout below artifacts/language/ (see MigratedLanguageFilePaths):
<build>/messages/LC_MESSAGES/<module>.<lang>.mo: the shipped state of a module, see ShippedTranslations::compile();<build>/keys/<module>.php: all identifiers of the module's .po files and template, the same for every language, as a PHP file for the opcache;<build>/locale/: the locale native gettext is activated with (see NativeGettext), a copy of "C.utf8" (glibc only);<build>/manifest.json: size and hash of every file, to tell an intact build, the hash of each built .po (see servesShippedPo()), the warnings and collisions, whether it ships a locale and the building platform (see platformProblem());current.json (glibc) and current-system.json (system locale, see NativeGettext::usesSystemLocale()): the build the runtime of that locale kind serves, its languages per module, every contributed module ("shipped") and a fingerprint of the built files ("sources") - read on every request, so nothing else. A build writes only the pointer of its kind and keeps the builds of the other one, so a build on the host (e.g. macOS) does not take a build of the web server (e.g. a glibc container) away.The build id fingerprints everything that determines the build: the shipped files, the compiling code (see FORMAT_VERSION) and the locale (or the platform using a system locale). An intact build with the same id (its manifest also keeps its warnings) is reused, otherwise a new one is written into a temporary directory and renamed to its id. Either way it is checked with a real native gettext lookup before its pointer is switched atomically; running requests keep their build. The previous build is kept, older ones (and the files of the former layout <lang>/<module>.mo, index.json) are removed. Builds are serialized by build.lock.
A .po that cannot be compiled is reported and served with the catalog of the served (or else the previous) build, so a broken file never turns a working language into -identifier-; without such a catalog the module is not served for that language. Values with disallowed markup are compiled cleaned and reported; identifiers with different values in several modules (txt() serves the one loaded last) are listed, grouped by modules (collision_summary) when the build is written. All of that stays in the manifest until fixed.
Files are written without fsync(): a build can be repeated any time, and the manifest reveals a build damaged by a crash.
@phpstan-type Manifest array{files: array<string, array{0: int, 1: string}>, sample: array{module: string, lang: string, key: string, value: string}, languages: array<string, list<string>>, hashes: array<string, array<string, string>>, warnings: list<string>, collisions: list<string>, compatibility: string, locale: 'shipped'|'system', platform: string} @phpstan-type Pointer array{build: ?string, previous: ?string, modules: array<string, list<string>>, shipped: ?list<string>, sources: ?string}
Definition at line 73 of file ShippedTranslationsBuild.php.
| ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild::__construct | ( | private readonly LanguageFileDirectoryManager | $language_file_directory_manager, |
| private readonly string | $ilias_absolute_path, | ||
| private readonly ShippedTranslations | $shipped_translations = new ShippedTranslations(), |
||
| private readonly ?string | $locale_source = null |
||
| ) |
| string | null | $locale_source | the locale directory to ship; default: found in LOCALE_SOURCES |
Definition at line 126 of file ShippedTranslationsBuild.php.
|
private |
| array{module | string, lang: string, key: string, value: string} $sample |
Definition at line 592 of file ShippedTranslationsBuild.php.
References Vendor\Package\$sample.
|
private |
Looks $sample up through native gettext in the build $build_directory.
| array{module | string, lang: string, key: string, value: string} $sample |
| RuntimeException | if native gettext does not serve the expected value |
Definition at line 575 of file ShippedTranslationsBuild.php.
References Vendor\Package\$sample.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
private |
| list<string> | $source_parts see sourceParts() | |
| string | null | $locale_source | null: no locale is shipped, see NativeGettext::usesSystemLocale() |
Definition at line 685 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
staticprivate |
Fingerprint of the compiling and cleaning code: formerCatalog() only takes over catalogs with the same one.
Definition at line 498 of file ShippedTranslationsBuild.php.
|
staticprivate |
| list<class-string> | $classes |
Definition at line 734 of file ShippedTranslationsBuild.php.
|
private |
Over the code that determines the build, see FORMAT_VERSION.
Definition at line 721 of file ShippedTranslationsBuild.php.
|
private |
| array<string,array{0 | int, 1: string}> $files the manifest, extended by the copied files |
Definition at line 803 of file ShippedTranslationsBuild.php.
References $files, and ILIAS\Scripts\PHPStan\$target.
|
private |
Over the content of every file below $directory - a locale copied from another version of the C library may not be loadable by the one in use.
Definition at line 749 of file ShippedTranslationsBuild.php.
|
private |
Definition at line 989 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\run().
Here is the caller graph for this function:
|
private |
The identifiers with different values in several modules, per language.
| array<string,array<string,array<string,string>>> | $values_per_language lang => module => identifier => value |
Definition at line 533 of file ShippedTranslationsBuild.php.
References $module, and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().
Here is the call graph for this function:
|
private |
| RuntimeException | if no locale to ship is found |
Definition at line 786 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
private |
Every shipped .po of every contributed directory with a module prefix (the main lang/ directory has none and holds no .po), per module.
| callable(string) | void $inform |
.po files, sorted by module (languages: lang => shipped .po, sorted by language), and every contributed module, sorted Definition at line 622 of file ShippedTranslationsBuild.php.
References Vendor\Package\$e, $module, $pattern, and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
The catalog of $module/$lang_key in the first former build that has it intact and compiled the same way (see catalogCompatibility()).
The bytes are taken over, not recompiled: reading a .mo back would shift plural forms (see TranslationCatalog::fromMoString()). Values are checked against the markup policy again.
| list<string> | $former_builds build ids |
.po it was compiled from Definition at line 445 of file ShippedTranslationsBuild.php.
|
staticprivate |
Definition at line 1006 of file ShippedTranslationsBuild.php.
References $module.
|
private |
Whether $directory (of the former layout <lang>/<module>.mo) holds nothing but catalogs and temporary files of them.
Definition at line 947 of file ShippedTranslationsBuild.php.
|
private |
Whether every file of $manifest is in $build_directory as it was written - without fsync(), a crash can leave empty or truncated files behind.
| array{files | array<string, array{0: int, 1: string}>} $manifest |
Definition at line 874 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
private |
Definition at line 762 of file ShippedTranslationsBuild.php.
References $files.
|
static |
Why a build made with a system locale (macOS/BSD) cannot be activated by a PHP needing the shipped one.
Definition at line 1045 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\TranslationGettextRepository\state(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testPlatformProblemIsNullForAShippedLocaleBuildAndForAManifestOfAFormerVersion(), and ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testPlatformProblemTellsASystemLocaleBuildOnlyWhereTheShippedLocaleIsNeeded().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 819 of file ShippedTranslationsBuild.php.
References $data, $files, $module, and Vendor\Package\$sample.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
static |
The pointer of this PHP's locale kind in $artifact_directory, null if it is missing or not valid.
null in a pointer written before it was recorded Definition at line 254 of file ShippedTranslationsBuild.php.
References ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\readPointerOf(), and ILIAS\Language\ComponentTranslation\NativeGettext\usesSystemLocale().
Referenced by ILIAS\Language\ComponentTranslation\MigratedTranslations\pointer(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testEveryContributedModuleIsRecordedAlsoWithoutAnyPoAndWithoutABuild(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testOnlyTheCurrentAndThePreviousBuildStayAndUnrelatedFilesAreLeftAlone(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testReadPointerTakesOnlyValidModulesOfTheShippedList(), and ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testRebuildingAnEarlierStateSwitchesBackWithoutLosingThePreviousBuild().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
null in a pointer written before it was recorded or without a build Definition at line 263 of file ShippedTranslationsBuild.php.
References $data, $module, ILIAS\Language\ComponentTranslation\MigratedLanguageFilePaths\buildPointerFileOf(), ILIAS\Language\ComponentTranslation\MigratedLanguageFilePaths\isBuildId(), ILIAS\Language\ComponentTranslation\MigratedLanguageFilePaths\isValidLanguageKey(), and ILIAS\Language\ComponentTranslation\MigratedLanguageFilePaths\isValidModule().
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\readPointer(), ILIAS\Language\ComponentTranslation\MigratedTranslations\reportNewerOtherBuild(), and ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testBuildsOfTheOtherLocaleKindAndTheirPointerSurviveTheCleanup().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 996 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
private |
Removes everything of a former build of this locale kind except the builds $keep: other builds, temporary directories and files of aborted builds, and the former layout (<lang>/<module>.mo, index.json).
Anything else stays, also everything of the other kind (whose build may run at the same time where the lock does not work, e.g. across a Docker Desktop mount).
| list<string> | $keep build ids |
Definition at line 917 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
private |
Removes $path recursively - only below $artifact_directory, and without following a symbolic link (a link itself is removed).
Definition at line 962 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild::run | ( | callable | $inform | ) |
| callable(string | $message): void $inform progress and warnings |
null without any migrated module); compiled: .po files compiled (0 for an unchanged build); rebuilt: the build was written now, not reused; removed: files and directories of former builds; collision_summary: the collisions grouped by modules, only if rebuilt; manifest: the manifest of the served build, relative to the ILIAS directory; markup_warnings: how many of the warnings are about disallowed markup; other_warnings: the rest | RuntimeException | if the build cannot be written, the locale is missing, or native gettext does not serve it - the pointer is left unchanged then |
Definition at line 145 of file ShippedTranslationsBuild.php.
References ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\ensureDirectory(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked(), and ILIAS\Language\ComponentTranslation\MigratedLanguageFilePaths\shippedArtifactDirectory().
Here is the call graph for this function:
|
private |
| callable(string | $message): void $inform |
Definition at line 167 of file ShippedTranslationsBuild.php.
References Vendor\Package\$e, ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\assertNativeGettextServes(), ILIAS\Language\ComponentTranslation\MigratedLanguageFilePaths\buildDirectory(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\buildId(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\findLocaleSource(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\findShippedFiles(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\isIntact(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\readManifest(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\readPointer(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\relativePath(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\removeObsolete(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\removeTree(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\sourceParts(), ILIAS\Language\ComponentTranslation\NativeGettext\usesSystemLocale(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\write(), and ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\writePointer().
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\run().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Whether the build of $artifact_directory serves exactly the shipped .po $shipped_po of $module for $lang_key (its content hash, see the manifest) - false without a build or after a change of the .po since (e.g.
by "merge", see ShippedPoMerger).
Definition at line 1025 of file ShippedTranslationsBuild.php.
References $module.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testServesShippedPoIsFalseWhenTheManifestOfTheCurrentBuildHasNoHashes(), ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testServesShippedPoIsFalseWhenTheManifestOfTheCurrentBuildIsGone(), and ILIAS\Language\ComponentTranslation\ShippedTranslationsBuildTest\testServesShippedPoIsTrueOnlyForThePoTheBuildWasMadeFrom().
Here is the caller graph for this function:
|
private |
| array<string,array{directory | LanguageFileDirectory, languages: array<string, string>, template: ?string}> $modules |
Definition at line 701 of file ShippedTranslationsBuild.php.
References $files, and $module.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 1067 of file ShippedTranslationsBuild.php.
|
private |
The identifiers of $module in its template (.pot), [] if there is none or it cannot be read (reported).
| list<string> | $warnings |
Definition at line 510 of file ShippedTranslationsBuild.php.
References Vendor\Package\$e, and $module.
|
private |
Writes the build $build_id into a temporary directory and renames that to $build_directory.
| array<string,array{directory | LanguageFileDirectory, languages: array<string, string>, template: ?string}> $modules |
| list<string> | $former_builds where the catalog of a .po that cannot be compiled is taken from |
.po files and the collisions grouped by modules (see findCollisions()) Definition at line 316 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
private |
Definition at line 982 of file ShippedTranslationsBuild.php.
|
private |
| Pointer | $pointer |
Definition at line 896 of file ShippedTranslationsBuild.php.
Referenced by ILIAS\Language\ComponentTranslation\ShippedTranslationsBuild\runLocked().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 104 of file ShippedTranslationsBuild.php.
|
staticprivate |
Definition at line 111 of file ShippedTranslationsBuild.php.
|
private |
The classes that determine the bytes of a compiled catalog (MigratedLanguageFileSync: moduleEntries()).
Definition at line 84 of file ShippedTranslationsBuild.php.
|
private |
Raise to rebuild when the output changes for a reason the fingerprint of the involved classes does not capture, e.g.
an update of the gettext library.
Definition at line 79 of file ShippedTranslationsBuild.php.
|
private |
Where the C library's "C.utf8" locale is looked for (Debian/Ubuntu, Fedora/RHEL, Arch, ...).
Definition at line 116 of file ShippedTranslationsBuild.php.
|
private |
Definition at line 97 of file ShippedTranslationsBuild.php.
|
private |
Definition at line 94 of file ShippedTranslationsBuild.php.
|
private |
Definition at line 95 of file ShippedTranslationsBuild.php.