Unverified Commit 53bc94e2 authored by Adrien Clairembault's avatar Adrien Clairembault Committed by GitHub
Browse files

Allow multiple custom locales files (#9180)

* Allow multiple custom locale files

* Use Toolbox::startsWith
parent ae81ac80
...@@ -360,17 +360,32 @@ class Plugin extends CommonDBTM { ...@@ -360,17 +360,32 @@ class Plugin extends CommonDBTM {
); );
} }
$mofile = str_replace($locales_dir, GLPI_LOCAL_I18N_DIR . '/'.$plugin_key . '/', $mofile); $plugin_folders = scandir(GLPI_LOCAL_I18N_DIR);
$phpfile = str_replace('.mo', '.php', $mofile); $plugin_folders = array_filter($plugin_folders, function($dir) use ($plugin_key) {
if (!is_dir(GLPI_LOCAL_I18N_DIR . "/$dir")) {
return false;
}
// Load local PHP file if it exists if ($dir == $plugin_key) {
if (file_exists($phpfile)) { return true;
$TRANSLATE->addTranslationFile('phparray', $phpfile, $plugin_key, $coretrytoload); }
}
// Load local MO file if it exists -- keep last so it gets precedence return Toolbox::startsWith($dir, $plugin_key . '_');
if (file_exists($mofile)) { });
$TRANSLATE->addTranslationFile('gettext', $mofile, $plugin_key, $coretrytoload);
foreach ($plugin_folders as $plugin_folder) {
$mofile = str_replace($locales_dir, GLPI_LOCAL_I18N_DIR . '/'. $plugin_folder . '/', $mofile);
$phpfile = str_replace('.mo', '.php', $mofile);
// Load local PHP file if it exists
if (file_exists($phpfile)) {
$TRANSLATE->addTranslationFile('phparray', $phpfile, $plugin_key, $coretrytoload);
}
// Load local MO file if it exists -- keep last so it gets precedence
if (file_exists($mofile)) {
$TRANSLATE->addTranslationFile('gettext', $mofile, $plugin_key, $coretrytoload);
}
} }
} }
......
...@@ -637,17 +637,32 @@ class Session { ...@@ -637,17 +637,32 @@ class Session {
$TRANSLATE->addTranslationFile('gettext', GLPI_I18N_DIR.$newfile, 'glpi', $trytoload); $TRANSLATE->addTranslationFile('gettext', GLPI_I18N_DIR.$newfile, 'glpi', $trytoload);
$mofile = GLPI_LOCAL_I18N_DIR . '/core/' . $newfile; $core_folders = scandir(GLPI_LOCAL_I18N_DIR);
$phpfile = str_replace('.mo', '.php', $mofile); $core_folders = array_filter($core_folders, function($dir) {
if (!is_dir(GLPI_LOCAL_I18N_DIR . "/$dir")) {
return false;
}
// Load local PHP file if it exists if ($dir == 'core') {
if (file_exists($phpfile)) { return true;
$TRANSLATE->addTranslationFile('phparray', $phpfile, 'glpi', $trytoload); }
}
// Load local MO file if it exists -- keep last so it gets precedence return Toolbox::startsWith($dir, 'core_');
if (file_exists($mofile)) { });
$TRANSLATE->addTranslationFile('gettext', $mofile, 'glpi', $trytoload);
foreach ($core_folders as $core_folder) {
$mofile = GLPI_LOCAL_I18N_DIR . "/$core_folder/" . $newfile;
$phpfile = str_replace('.mo', '.php', $mofile);
// Load local PHP file if it exists
if (file_exists($phpfile)) {
$TRANSLATE->addTranslationFile('phparray', $phpfile, 'glpi', $trytoload);
}
// Load local MO file if it exists -- keep last so it gets precedence
if (file_exists($mofile)) {
$TRANSLATE->addTranslationFile('gettext', $mofile, 'glpi', $trytoload);
}
} }
// Load plugin dicts // Load plugin dicts
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment