Merge pull request #47 from Orange-Management/dynamic-language-loading

Dynamic language loading
This commit is contained in:
Dennis Eichhorn 2016-07-05 19:23:40 +02:00 committed by GitHub
commit a3be580f2a
2 changed files with 9 additions and 5 deletions

View File

@ -17,6 +17,7 @@ namespace phpOMS\Localization;
use phpOMS\Log\FileLogger; use phpOMS\Log\FileLogger;
use phpOMS\Log\LoggerInterface; use phpOMS\Log\LoggerInterface;
use phpOMS\Module\ModuleAbstract;
/** /**
* Localization class. * Localization class.
@ -134,6 +135,7 @@ class L11nManager
* *
* @param string $code Country code * @param string $code Country code
* @param string $module Module name * @param string $module Module name
* @param string $theme Theme
* @param string $translation Text * @param string $translation Text
* *
* @return array * @return array
@ -141,15 +143,16 @@ class L11nManager
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getText(string $code, string $module, string $translation) public function getText(string $code, string $module, string $theme, string $translation)
{ {
if (!isset($this->language[$code][$module][$translation])) { if (!isset($this->language[$code][$module][$translation])) {
/** @var ModuleAbstract $class */
$class = '\Modules\\' . $module . '\\Controller'; $class = '\Modules\\' . $module . '\\Controller';
$this->loadLanguage($code, $module, $class::getLocalization($code, $module)); $this->loadLanguage($code, $module, $class::getLocalization($code, $theme));
if (!isset($this->language[$code][$module][$translation])) { if (!isset($this->language[$code][$module][$translation])) {
$this->logger->warning(FileLogger::MSG_FULL, [ $this->logger->warning(FileLogger::MSG_FULL, [
'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.' 'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.',
]); ]);
return 'ERROR'; return 'ERROR';

View File

@ -296,6 +296,7 @@ class Localization
* Get translation. * Get translation.
* *
* @param string $module Module name * @param string $module Module name
* @param string $theme Theme name
* @param string $translation Text * @param string $translation Text
* *
* @return array * @return array
@ -303,8 +304,8 @@ class Localization
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getText(string $module, string $translation) public function getText(string $module, string $theme, string $translation)
{ {
return $this->l11nManager->getText($this->language, $module, $translation); return $this->l11nManager->getText($this->language, $module, $theme, $translation);
} }
} }