From b60b81133575ed763da0e95a62fddd1bb9a99fb5 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 2 Sep 2014 16:51:17 +0200 Subject: [PATCH] ApplicationBootstrap: list "core" translations Just to make application fit module capabilities. We might find a better place for both later on. refs #7054 --- .../Application/ApplicationBootstrap.php | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index 3f68ce43b..7736f8cf9 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -452,9 +452,8 @@ abstract class ApplicationBootstrap */ protected function setupInternationalization() { - $localeDir = $this->getApplicationDir('locale'); - if (file_exists($localeDir) && is_dir($localeDir)) { - Translator::registerDomain(Translator::DEFAULT_DOMAIN, $localeDir); + if ($this->hasLocales()) { + Translator::registerDomain(Translator::DEFAULT_DOMAIN, $this->getLocaleDir()); } try { @@ -469,4 +468,48 @@ abstract class ApplicationBootstrap return $this; } + + /** + * @return string Our locale directory + */ + public function getLocaleDir() + { + return $this->getApplicationDir('locale'); + } + + /** + * return bool Whether Icinga Web has translations + */ + public function hasLocales() + { + $localedir = $this->getLocaleDir(); + return file_exists($localedir) && is_dir($localedir); + } + + /** + * List all available locales + * + * NOTE: Might be a candidate for a static function in Translator + * + * return array Locale list + */ + public function listLocales() + { + $locales = array(); + if (! $this->hasLocales()) { + return $locales; + } + $localedir = $this->getLocaleDir(); + + $dh = opendir($localedir); + while (false !== ($file = readdir($dh))) { + $filename = $localedir . DIRECTORY_SEPARATOR . $file; + if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $file) && is_dir($filename)) { + $locales[] = $file; + } + } + closedir($dh); + sort($locales); + return $locales; + } }