From 6c570fb63ce759cc7b866b925b4ed98fbed95099 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 5 Jul 2016 10:29:05 +0200 Subject: [PATCH 1/2] Dynamic language loading This allows dynamic language loading. Could however conflict with the language loading for the navigation module? --- Localization/L11nManager.php | 15 ++++++++++----- Module/ModuleAbstract.php | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Localization/L11nManager.php b/Localization/L11nManager.php index 5264d6fd7..5304c59c1 100644 --- a/Localization/L11nManager.php +++ b/Localization/L11nManager.php @@ -118,7 +118,7 @@ class L11nManager * @since 1.0.0 * @author Dennis Eichhorn */ - public function getLanguage(string $language, string $module = null) : array + public function getModuleLanguage(string $language, string $module = null) : array { if (!isset($module) && isset($this->language[$language])) { return $this->language[$language]; @@ -144,11 +144,16 @@ class L11nManager public function getText(string $code, string $module, string $translation) { if (!isset($this->language[$code][$module][$translation])) { - $this->logger->warning(FileLogger::MSG_FULL, [ - 'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.' - ]); + $class = '\Modules\\' . $module . '\\Controller'; + $this->loadLanguage($code, $module, $class::getLocalization($code, $module)); - return 'ERROR'; + if (!isset($this->language[$code][$module][$translation])) { + $this->logger->warning(FileLogger::MSG_FULL, [ + 'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.' + ]); + + return 'ERROR'; + } } return $this->language[$code][$module][$translation]; diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index f565341c3..27b42437d 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -128,7 +128,7 @@ abstract class ModuleAbstract * @since 1.0.0 * @author Dennis Eichhorn */ - public function getLocalization(string $language, string $destination) : array + public static function getLocalization(string $language, string $destination) : array { $lang = []; if (($path = realpath($oldPath = __DIR__ . '/../../Modules/' . static::MODULE_NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) !== false) { From e7a016cb07eccbe7b72622a638dae3d6127f0f35 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 5 Jul 2016 10:29:16 +0200 Subject: [PATCH 2/2] Dynamic language loading --- Module/ModuleManager.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index ad6a70c2a..c897ee18e 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -648,8 +648,6 @@ class ModuleManager { $this->running[$module] = ModuleFactory::getInstance($module, $this->app); $this->app->dispatcher->set($this->running[$module], '\Modules\\' . $module . '\\Controller'); - // todo: replace 'en' with request language. - $this->loadLanguage($module, 'en'); } /** @@ -670,23 +668,4 @@ class ModuleManager return $this->running[$module]; } - - /** - * Load module language. - * - * @param string $module Module name - * @param string $language Language - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function loadLanguage(string $module, string $language) - { - $file = $this->running[$module]->getLocalization($language, $this->app->appName); - if (!empty($file)) { - $this->app->l11nManager->loadLanguage($language, $module, $file); - } - } }