From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../application/clicommands/CompileCommand.php | 40 ++++++ .../application/clicommands/RefreshCommand.php | 40 ++++++ .../application/clicommands/TestCommand.php | 140 +++++++++++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 modules/translation/application/clicommands/CompileCommand.php create mode 100644 modules/translation/application/clicommands/RefreshCommand.php create mode 100644 modules/translation/application/clicommands/TestCommand.php (limited to 'modules/translation/application') diff --git a/modules/translation/application/clicommands/CompileCommand.php b/modules/translation/application/clicommands/CompileCommand.php new file mode 100644 index 0000000..8408009 --- /dev/null +++ b/modules/translation/application/clicommands/CompileCommand.php @@ -0,0 +1,40 @@ + + * + * EXAMPLES: + * + * icingacli translation compile demo de_DE + * icingacli translation compile demo fr_FR + */ + public function moduleAction() + { + $module = $this->validateModuleName($this->params->shift()); + $locale = $this->validateLocaleCode($this->params->shift()); + + $helper = $this->getTranslationHelper($locale); + $helper->compileModuleTranslation($module); + } +} diff --git a/modules/translation/application/clicommands/RefreshCommand.php b/modules/translation/application/clicommands/RefreshCommand.php new file mode 100644 index 0000000..b4b2dc0 --- /dev/null +++ b/modules/translation/application/clicommands/RefreshCommand.php @@ -0,0 +1,40 @@ + + * + * EXAMPLES: + * + * icingacli translation refresh module demo de_DE + * icingacli translation refresh module demo fr_FR + */ + public function moduleAction() + { + $module = $this->validateModuleName($this->params->shift()); + $locale = $this->validateLocaleCode($this->params->shift()); + + $helper = $this->getTranslationHelper($locale); + $helper->updateModuleTranslations($module); + } +} diff --git a/modules/translation/application/clicommands/TestCommand.php b/modules/translation/application/clicommands/TestCommand.php new file mode 100644 index 0000000..347c2c9 --- /dev/null +++ b/modules/translation/application/clicommands/TestCommand.php @@ -0,0 +1,140 @@ + + * + * EXAMPLES: + * + * icingacli translation test dateformatter de_DE + * icingacli translation test dateformatter fr_FR + */ + public function dateformatterAction() + { + $time = time(); + + /** @uses DateFormatter::timeAgo */ + $this->printTable($this->getMultiTranslated( + 'Time Ago', + array('Icinga\Date\DateFormatter', 'timeAgo'), + array( + "15 sec" => $time - 15, + "62 sec" => $time - 62, + "10 min" => $time - 600, + "1h" => $time - 1 * 3600, + "3h" => $time - 3 * 3600, + "25h" => $time - 25 * 3600, + "31d" => $time - 31 * 24 * 3600, + ) + )); + + $this->printTable($this->getMultiTranslated( + 'Time Since', + array('Icinga\Date\DateFormatter', 'timeSince'), + array( + "15 sec" => $time - 15, + "62 sec" => $time - 62, + "10 min" => $time - 600, + "1h" => $time - 1 * 3600, + "3h" => $time - 3 * 3600, + "25h" => $time - 25 * 3600, + "31d" => $time - 31 * 24 * 3600, + ) + )); + + $this->printTable($this->getMultiTranslated( + 'Time Until', + array('Icinga\Date\DateFormatter', 'timeUntil'), + array( + "15 sec" => $time + 15, + "62 sec" => $time + 62, + "10 min" => $time + 600, + "1h" => $time + 1 * 3600, + "3h" => $time + 3 * 3600, + "25h" => $time + 25 * 3600, + "31d" => $time + 31 * 24 * 3600, + ) + )); + } + + public function defaultAction() + { + $this->dateformatterAction(); + } + + public function init() + { + foreach ($this->params->getAllStandalone() as $l) { + $this->locales[] = $l; + } + + if (empty($this->locales)) { + /** @var GettextTranslator $translator */ + $translator = StaticTranslator::$instance; + $this->locales = $translator->listLocales(); + } + } + + protected function callTranslated($callback, $arguments, $locale = 'en_US') + { + /** @var GettextTranslator $translator */ + $translator = StaticTranslator::$instance; + $translator->setLocale($locale); + return call_user_func_array($callback, $arguments); + } + + protected function getMultiTranslated($name, $callback, $arguments, $locales = null) + { + if ($locales === null) { + $locales = $this->locales; + } + array_unshift($locales, 'C'); + + $rows = array(); + + foreach ($arguments as $k => $args) { + $row = array($name => $k); + + if (! is_array($args)) { + $args = array($args); + } + foreach ($locales as $locale) { + $row[$locale] = $this->callTranslated($callback, $args, $locale); + } + $rows[] = $row; + } + + return $rows; + } + + protected function printTable($rows) + { + $tt = new ArrayToTextTableHelper($rows); + $tt->showHeaders(true); + $tt->render(); + echo "\n\n"; + } +} -- cgit v1.2.3