diff --git a/Localization/Localization.php b/Localization/Localization.php index 1173f03ae..49281cae4 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -31,13 +31,6 @@ use phpOMS\Datatypes\Exception\InvalidEnumValue; class Localization { - /** - * Localization manager. - * - * @var L11nManager - * @since 1.0.0 - */ - public $l11nManager = null; /** * Country ID. * @@ -136,9 +129,8 @@ class Localization * @since 1.0.0 * @author Dennis Eichhorn */ - public function __construct(L11nManager $l11nManager = null) + public function __construct() { - $this->l11nManager = $l11nManager; } /** @@ -323,22 +315,5 @@ class Localization public function setThousands(string $thousands) { $this->thousands = $thousands; - } - - /** - * Get translation. - * - * @param string $module Module name - * @param string $theme Theme name - * @param string $translation Text - * - * @return array - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function getText(string $module, string $theme, string $translation) - { - return $this->l11nManager->getText($this->language, $module, $theme, $translation); - } + } } diff --git a/Views/View.php b/Views/View.php index 58607de75..e142b2fa6 100644 --- a/Views/View.php +++ b/Views/View.php @@ -338,6 +338,33 @@ class View implements \Serializable $this->data[$id] = $data; } + /** + * Get translation. + * + * @param string $module Module name + * @param string $theme Theme name + * @param string $translation Text + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getText(string $translation, string $module = null, string $theme = null) + { + if(!isset($module)) { + $match = '/Theme/'; + $module = ($start = strripos($this->template, $match)) !== false ? substr($this->template, ($offset = $start+strlen($match)), strpos($this->template, '/', $offset)) : throw new \Exception('Unknown Theme'); + } + + if(!isset($theme)) { + $match = '/Modules/'; + $module = ($start = strripos($this->template, $match)) !== false ? substr($this->template, ($offset = $start+strlen($match)), strpos($this->template, '/', $offset)) : throw new \Exception('Unknown Module'); + } + + return $this->app->l11nManager->getText($this->l11n->getLanguage(), $module, $theme, $translation); + } + /** * Arrayify view and it's subviews. *