36 $this->codes = $codes;
47 $dir =
Paths::sanitize($dir, false);
49 if (is_dir(
"{$dir}/install/languages")) {
53 if (is_dir(
"{$dir}/languages")) {
57 $mods = new \DirectoryIterator(
"{$dir}/mod");
59 foreach ($mods as $mod) {
60 if ($mod->isDot() || !$mod->isDir()) {
69 if (is_dir(
"{$mod->getPathname()}/languages")) {
84 $dir =
Paths::sanitize($dir, false);
86 $files = new \DirectoryIterator($dir);
87 foreach ($files as $file) {
88 if ($file->isDot() || !$file->isFile()) {
92 if ($file->getExtension() !==
'php') {
96 $code = $file->getBasename(
'.php');
97 if (!in_array(
$code, $this->codes)) {
100 if (in_array(
$code, $this->codes)) {
102 rename($file->getPathname(),
"{$dir}/{$code}.php");
103 $this->log[] =
"Renamed {$file->getPathname()} to {$code}.php";
105 unlink($file->getPathname());
106 $this->log[] =
"Removed {$file->getPathname()}";
110 if (
$code !==
'en' && file_exists(
"{$dir}/{$code}.php")) {
113 $this->cleanupMissingTranslationParameters($dir,
$code);
114 $this->cleanupEmptyTranslations(
"{$dir}/{$code}.php");
128 $english =
Includer::includeFile(
"{$directory}/en.php");
129 $translation = Includer::includeFile(
"{$directory}/{$language_code}.php");
132 $english_matches = preg_match_all(
'/%[a-zA-Z]/m',
$value);
133 if (!array_key_exists(
$key, $translation) || $english_matches ===
false) {
137 $translation_matches = preg_match_all(
'/%[a-zA-Z]/m', $translation[
$key]);
138 if ($translation_matches !==
false && $english_matches === $translation_matches) {
142 $file_contents = file_get_contents(
"{$directory}/{$language_code}.php");
144 $pattern =
'/^\s*[\'"]' .
$key .
'[\'"] => [\'"]' . preg_quote($translation[
$key],
'/') .
'[\'"],{0,1}\R/m';
149 $pattern =
'/^\s*[\'"]' .
$key .
'[\'"] => [\'"]' . preg_quote(addslashes($translation[
$key]),
'/') .
'[\'"],{0,1}\R/m';
155 file_put_contents(
"{$directory}/{$language_code}.php",
$file_contents);
157 $this->
log[] =
"Unable to repair mismatch in translation argument count in {$directory}/{$language_code}.php for the key '{$key}'";
170 $contents = file_get_contents($translation_file);
175 $pattern =
'/^\s*[\'"].*[\'"] => [\'"]{2},{0,1}\R/m';
181 file_put_contents($translation_file,
$contents);
185 $this->log[] =
"Cleaned empty translations from {$translation_file}";
187 unlink($translation_file);
189 $this->log[] =
"Removed empty translation file {$translation_file}";
203 return preg_replace(
'~[^a-z0-9]~',
'_',
$code);
215 $english =
Includer::includeFile(
"{$directory}/en.php");
216 $translation = Includer::includeFile(
"{$directory}/{$language_code}.php");
219 if (array_key_exists(
$key, $english)) {
223 $this->log[] =
"The translation key '{$key}' exists in the '{$language_code}' translation but not in English";
236 $english =
Includer::includeFile(
"{$directory}/en.php");
237 $translation = Includer::includeFile(
"{$directory}/{$language_code}.php");
240 if (!array_key_exists(
$key, $english)) {
245 if (strlen(
$key) < 3) {
254 $this->log[] =
"The translation key '{$key}' in the '{$language_code}' translation is identical to the English translation";
log($level, $message, array $context=[])
Log a message.
Persistent, installation-wide key-value storage.
Removes invalid language files from an installation.
__construct(array $codes=[])
Constructor.
cleanupMissingTranslationParameters(string $directory, string $language_code)
Try to cleanup translations with a different argument count than English as this can cause failed tra...
detectIdenticalTranslations(string $directory, string $language_code)
Detect identical translations, this could be due to a wrong Transifex import.
cleanLanguagesDir(string $dir)
Clean up a languages dir.
cleanInstallation(string $dir)
Clean up within an installation.
cleanupEmptyTranslations(string $translation_file)
Remove empty translations from a translation file.
detectAdditionalKeys(string $directory, string $language_code)
Detect translation keys that (still) exist in a translation but no longer in the English translation.
normalizeLanguageCode(string $code)
Normalize a language code (e.g.
Allow executing scripts without $this context or local vars.
Find Elgg and project paths.
_elgg_services()
Get the global service provider.
foreach(array_keys($combine_languages) as $language) $translations
if(!empty($title) &&!empty($icon_name)) if(!empty($title)) if(!empty($menu)) if(!empty($header)) if(!empty($body)) $contents
if(! $plugin instanceof \ElggPlugin) $file_contents
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key