diff --git a/src/Common/View/Helper/SubMenu.php b/src/Common/View/Helper/SubMenu.php index ce60b15..4b153b8 100644 --- a/src/Common/View/Helper/SubMenu.php +++ b/src/Common/View/Helper/SubMenu.php @@ -41,12 +41,15 @@ namespace Soflomo\Common\View\Helper; use Zend\View\Helper\AbstractHelper; +use Zend\I18n\Translator\Translator; class SubMenu extends AbstractHelper { protected $level = 0; protected $class; protected $header; + protected $translator; + protected $textdomain; public function __invoke() { @@ -71,6 +74,13 @@ public function setHeader($header) return $this; } + public function setTranslator(Translator $translator, $textdomain = 'default') + { + $this->translator = $translator; + $this->textdomain = $textdomain; + return $this; + } + public function __toString() { $view = $this->getView(); @@ -97,6 +107,15 @@ public function __toString() $flag = $container->isVisible(); $container->setVisible(true); + // Inject translator + $enabled = $menu->isTranslatorEnabled(); + $translator = $menu->getTranslator(); + $textdomain = $menu->getTranslatorTextDomain(); + if ($this->translator) { + $menu->setTranslator($this->translator, $this->textdomain); + $menu->setTranslatorEnabled(true); + } + $html = $menu->setContainer($container) ->setUlClass('') ->setOnlyActiveBranch(false) @@ -108,12 +127,19 @@ public function __toString() $container->setVisible($flag); // Reset the container $menu->setContainer($current); + // Reset translator + $menu->setTranslatorEnabled($enabled); + $menu->setTranslator($translator, $textdomain); if (!strlen($html)) { return ''; } $label = $this->header ?: $container->getLabel(); + if ($this->translator) { + $label = $this->translator->translate($label, $this->textdomain); + } + return sprintf('