DashboardCommand: Utilize ipl-i18n in `sections` command
This commit is contained in:
parent
573af6b2df
commit
d83b06618a
|
@ -9,8 +9,8 @@ use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Modules\DashboardContainer;
|
use Icinga\Application\Modules\DashboardContainer;
|
||||||
use Icinga\Cli\Command;
|
use Icinga\Cli\Command;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Exception\IcingaException;
|
use ipl\I18n\GettextTranslator;
|
||||||
use Icinga\Util\Translator;
|
use ipl\I18n\StaticTranslator;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
|
||||||
class DashboardCommand extends Command
|
class DashboardCommand extends Command
|
||||||
|
@ -34,25 +34,23 @@ class DashboardCommand extends Command
|
||||||
// Calling getDashboard() results in Url::fromPath() getting called as well == the CLI's death
|
// Calling getDashboard() results in Url::fromPath() getting called as well == the CLI's death
|
||||||
$paneItemsProperty = $moduleReflection->getProperty('paneItems');
|
$paneItemsProperty = $moduleReflection->getProperty('paneItems');
|
||||||
$paneItemsProperty->setAccessible(true);
|
$paneItemsProperty->setAccessible(true);
|
||||||
// Again, no direct way to access this nor to let the module setup its own translation domain
|
|
||||||
$localeDirProperty = $moduleReflection->getProperty('localedir');
|
|
||||||
$localeDirProperty->setAccessible(true);
|
|
||||||
|
|
||||||
$locales = Translator::getAvailableLocaleCodes();
|
/** @var GettextTranslator $translator */
|
||||||
$modules = Icinga::app()->getModuleManager()->loadEnabledModules()->getLoadedModules();
|
$translator = StaticTranslator::$instance;
|
||||||
|
|
||||||
|
$locales = $translator->listLocales();
|
||||||
|
$modules = Icinga::app()->getModuleManager()->getLoadedModules();
|
||||||
foreach ($this->listDashboardConfigs() as $path) {
|
foreach ($this->listDashboardConfigs() as $path) {
|
||||||
Logger::info('Migrating dashboard config: %s', $path);
|
Logger::info('Migrating dashboard config: %s', $path);
|
||||||
|
|
||||||
$config = Config::fromIni($path);
|
$config = Config::fromIni($path);
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
$localePath = $localeDirProperty->getValue($module);
|
if (! $module->hasLocales()) {
|
||||||
if (! is_dir($localePath)) {
|
|
||||||
// Modules without any translations are not affected
|
// Modules without any translations are not affected
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$launchConfigScriptMethod->invoke($module);
|
$launchConfigScriptMethod->invoke($module);
|
||||||
Translator::registerDomain($module->getName(), $localePath);
|
|
||||||
|
|
||||||
foreach ($locales as $locale) {
|
foreach ($locales as $locale) {
|
||||||
if ($locale === 'en_US') {
|
if ($locale === 'en_US') {
|
||||||
|
@ -60,8 +58,8 @@ class DashboardCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Translator::setupLocale($locale);
|
$translator->setLocale($locale);
|
||||||
} catch (IcingaException $e) {
|
} catch (Exception $e) {
|
||||||
Logger::debug('Ignoring locale "%s". Reason: %s', $locale, $e->getMessage());
|
Logger::debug('Ignoring locale "%s". Reason: %s', $locale, $e->getMessage());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue