Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add multiple translation text domains to Zend\Navigation #4979

Merged
merged 4 commits into from

3 participants

@shadowdani

Add a new option "textdomain" to a navigation page. If present, the navigation view helper passes it to the translator, allowing for multiple text domains in one container/navigation block.

Example config:

'navigation' => array(
    'default' => array(
        'page1' => array(
            'label'      => 'Page 1',
            'route'      => 'page1',
            'textdomain' => 'MyFirstModule'
        ),
        'page2' => array(
            'label'      => 'Page 2',
            'route'      => 'page2',
            'textdomain' => 'MySecondModule'
        ),
    )
)
EvanDotPro and others added some commits
@EvanDotPro EvanDotPro Merge PHLAK:hotfix/gravatar-trim-strtolower into master e702a42
Daniele Princiotta Zend\Navigation currently uses only one text domain for translating p…
…age labels. This commit adds the new option key "textdomain" to Navigation and its (translatable) view helpers. If the option is present, it is used during translation. If the key is not present, the old behavior is applied.
364cb34
Daniele Princiotta Fixed method names 6ca11ed
Daniele Princiotta Aligned method naming to zf style f448163
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#4979] CS fixes
- EOF ending
afc0044
@weierophinney weierophinney merged commit f448163 into zendframework:develop
@basz basz referenced this pull request from a commit
@basz basz Merge branch 'develop' of git://github.com/zendframework/zf2
# By Matthew Weier O'Phinney (7) and others
# Via Matthew Weier O'Phinney (63) and others
* 'develop' of git://github.com/zendframework/zf2: (40 commits)
  Fix tests for php <5.4
  Find traits with TokenArrayScanner
  Added test for issue #4989
  Fixed failing tests
  Renamed interface and extract HydrationInterface
  [#4979] CS fixes
  [#4969] CS fixes
  [#4931] CS fixes
  [#4912] Re-add removed method
  CS fixes
  Revert "Revert "Merge branch 'superdweebie-rand-bugfix'""
  Fix CS
  Correction for inverted version checks
  change of version checks to use PHP_VERSION_ID constant.
  Aligned method naming to zf style
  Fixed method names
  Zend\Navigation currently uses only one text domain for translating page labels. This commit adds the new option key "textdomain" to Navigation and its (translatable) view helpers. If the option is present, it is used during translation. If the key is not present, the old behavior is applied.
  Added unit test for should not convert to array recursively if model is traversable
  PartialLoop helper: prevent convert traversable model to array recursively
  Add test
  ...
35d0648
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-view
@weierophinney weierophinney Merge pull request zendframework/zf2#4979 from shadowdani/nav-textdomain
Add multiple translation text domains to Zend\Navigation
4f66433
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-view
@weierophinney weierophinney [zendframework/zf2#4979] CS fixes
- EOF ending
e2afc56
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-view
@weierophinney weierophinney Merge branch 'feature/4979' into develop bad76dc
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-navigation
@weierophinney weierophinney Merge pull request zendframework/zf2#4979 from shadowdani/nav-textdomain
Add multiple translation text domains to Zend\Navigation
8343641
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-navigation
@weierophinney weierophinney Merge branch 'feature/4979' into develop f598ea6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 16, 2013
  1. @EvanDotPro
Commits on Aug 17, 2013
  1. Zend\Navigation currently uses only one text domain for translating p…

    Daniele Princiotta authored
    …age labels. This commit adds the new option key "textdomain" to Navigation and its (translatable) view helpers. If the option is present, it is used during translation. If the key is not present, the old behavior is applied.
  2. Fixed method names

    Daniele Princiotta authored
  3. Aligned method naming to zf style

    Daniele Princiotta authored
This page is out of date. Refresh to see the latest.
View
34 library/Zend/Navigation/Page/AbstractPage.php
@@ -116,6 +116,13 @@
protected $permission;
/**
+ * Text domain for Translator
+ *
+ * @var string
+ */
+ protected $textDomain;
+
+ /**
* Whether this page should be considered active
*
* @var bool
@@ -733,6 +740,33 @@ public function getPermission()
}
/**
+ * Sets text domain for translation
+ *
+ * @param string|null $textDomain [optional] text domain to associate
+ * with this page. Default is null, which
+ * sets no text domain.
+ *
+ * @return AbstractPage fluent interface, returns self
+ */
+ public function setTextDomain($textDomain = null)
+ {
+ if (null !== $textDomain) {
+ $this->textDomain = $textDomain;
+ }
+ return $this;
+ }
+
+ /**
+ * Returns text domain for translation
+ *
+ * @return mixed|null text domain or null
+ */
+ public function getTextDomain()
+ {
+ return $this->textDomain;
+ }
+
+ /**
* Sets whether page should be considered active or not
*
* @param bool $active [optional] whether page should be
View
4 library/Zend/View/Helper/Navigation/AbstractHelper.php
@@ -397,7 +397,9 @@ public function htmlify(AbstractPage $page)
$title = $page->getTitle();
if (null !== ($translator = $this->getTranslator())) {
- $textDomain = $this->getTranslatorTextDomain();
+ if (null === ($textDomain = $page->getTextDomain())) {
+ $textDomain = $this->getTranslatorTextDomain();
+ }
if (is_string($label) && !empty($label)) {
$label = $translator->translate($label, $textDomain);
}
View
5 library/Zend/View/Helper/Navigation/Breadcrumbs.php
@@ -109,7 +109,10 @@ public function renderStraight($container = null)
} else {
$html = $active->getLabel();
if (null !== ($translator = $this->getTranslator())) {
- $html = $translator->translate($html, $this->getTranslatorTextDomain());
+ if (null === ($textDomain = $active->getTextDomain())) {
+ $textDomain = $this->getTranslatorTextDomain();
+ }
+ $html = $translator->translate($html, $textDomain);
}
$escaper = $this->view->plugin('escapeHtml');
$html = $escaper($html);
View
4 library/Zend/View/Helper/Navigation/Menu.php
@@ -477,7 +477,9 @@ public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToList
// translate label and title?
if (null !== ($translator = $this->getTranslator())) {
- $textDomain = $this->getTranslatorTextDomain();
+ if (null === ($textDomain = $page->getTextDomain())) {
+ $textDomain = $this->getTranslatorTextDomain();
+ }
if (is_string($label) && !empty($label)) {
$label = $translator->translate($label, $textDomain);
}
View
11 tests/ZendTest/Navigation/Page/PageTest.php
@@ -726,6 +726,17 @@ public function testSetVisibleShouldJuggleValue()
$this->assertFalse($page->isVisible());
}
+ public function testSetTranslatorTextDomainString()
+ {
+ $page = AbstractPage::factory(array(
+ 'type' => 'uri',
+ 'label' => 'hello'
+ ));
+
+ $page->setTextdomain('foo');
+ $this->assertEquals('foo', $page->getTextdomain());
+ }
+
public function testMagicOverLoadsShouldSetAndGetNativeProperties()
{
$page = AbstractPage::factory(array(
View
43 tests/ZendTest/View/Helper/Navigation/AbstractTest.php
@@ -75,6 +75,13 @@
*/
protected $_nav2;
+ /**
+ * The third container in the config file (files/navigation.xml)
+ *
+ * @var Navigation\Navigation
+ */
+ protected $_nav3;
+
private $_oldControllerDir;
/**
@@ -92,6 +99,7 @@ protected function setUp()
// setup containers from config
$this->_nav1 = new Navigation($config->get('nav_test1'));
$this->_nav2 = new Navigation($config->get('nav_test2'));
+ $this->_nav3 = new Navigation($config->get('nav_test3'));
// setup view
$view = new PhpRenderer();
@@ -204,4 +212,39 @@ protected function _getTranslator()
$translator->addTranslationFile('default', null);
return $translator;
}
+
+ /**
+ * Returns translator with text domain
+ *
+ * @return Translator
+ */
+ protected function _getTranslatorWithTextDomain()
+ {
+ $loader1 = new TestAsset\ArrayTranslator();
+ $loader1->translations = array(
+ 'Page 1' => 'TextDomain1 1',
+ 'Page 1.1' => 'TextDomain1 1.1',
+ 'Page 2' => 'TextDomain1 2',
+ 'Page 2.3' => 'TextDomain1 2.3',
+ 'Page 2.3.3' => 'TextDomain1 2.3.3',
+ 'Page 2.3.3.1' => 'TextDomain1 2.3.3.1',
+ );
+
+ $loader2 = new TestAsset\ArrayTranslator();
+ $loader2->translations = array(
+ 'Page 1' => 'TextDomain2 1',
+ 'Page 1.1' => 'TextDomain2 1.1',
+ 'Page 2' => 'TextDomain2 2',
+ 'Page 2.3' => 'TextDomain2 2.3',
+ 'Page 2.3.3' => 'TextDomain2 2.3.3',
+ 'Page 2.3.3.1' => 'TextDomain2 2.3.3.1',
+ );
+
+ $translator = new Translator();
+ $translator->getPluginManager()->setService('default1', $loader1);
+ $translator->getPluginManager()->setService('default2', $loader2);
+ $translator->addTranslationFile('default1', null, 'ZendTest_1');
+ $translator->addTranslationFile('default2', null, 'ZendTest_2');
+ return $translator;
+ }
}
View
9 tests/ZendTest/View/Helper/Navigation/BreadcrumbsTest.php
@@ -171,6 +171,15 @@ public function testTranslationUsingZendTranslate()
$this->assertEquals($expected, $this->_helper->render());
}
+ public function testTranslationUsingZendTranslateAndCustomTextDomain()
+ {
+ $this->_helper->setTranslator($this->_getTranslatorWithTextDomain());
+
+ $expected = $this->_getExpected('bc/textdomain.html');
+
+ $this->assertEquals($expected, $this->_helper->render($this->_nav3));
+ }
+
public function testTranslationUsingZendTranslateAdapter()
{
$translator = $this->_getTranslator();
View
9 tests/ZendTest/View/Helper/Navigation/MenuTest.php
@@ -219,6 +219,15 @@ public function testTranslationUsingZendTranslate()
$this->assertEquals($expected, $this->_helper->render());
}
+ public function testTranslationUsingZendTranslateWithTextDomain()
+ {
+ $translator = $this->_getTranslatorWithTextDomain();
+ $this->_helper->setTranslator($translator);
+
+ $expected = $this->_getExpected('menu/textdomain.html');
+ $this->assertEquals($expected, $this->_helper->render($this->_nav3));
+ }
+
public function testTranslationUsingZendTranslateAdapter()
{
$translator = $this->_getTranslator();
View
1  tests/ZendTest/View/Helper/Navigation/_files/expected/bc/textdomain.html
@@ -0,0 +1 @@
+<a href="page2">TextDomain1 2</a> &gt; <a href="page2/page2_3">Page 2.3</a> &gt; <a href="page2/page2_3/page2_3_3">TextDomain1 2.3.3</a> &gt; TextDomain2 2.3.3.1
View
48 tests/ZendTest/View/Helper/Navigation/_files/expected/menu/textdomain.html
@@ -0,0 +1,48 @@
+<ul class="navigation">
+ <li>
+ <a href="page1">Page 1</a>
+ <ul>
+ <li>
+ <a href="page1/page1_1">TextDomain1 1.1</a>
+ </li>
+ </ul>
+ </li>
+ <li class="active">
+ <a href="page2">TextDomain1 2</a>
+ <ul>
+ <li>
+ <a href="page2/page2_1">Page 2.1</a>
+ </li>
+ <li class="active">
+ <a href="page2/page2_2">Page 2.2</a>
+ <ul>
+ <li>
+ <a href="page2/page2_2/page2_2_1">Page 2.2.1</a>
+ </li>
+ <li class="active">
+ <a href="page2/page2_2/page2_2_2">Page 2.2.2</a>
+ </li>
+ </ul>
+ </li>
+ <li class="active">
+ <a href="page2/page2_3">Page 2.3</a>
+ <ul>
+ <li>
+ <a href="page2/page2_3/page2_3_1">Page 2.3.1</a>
+ </li>
+ <li class="active">
+ <a href="page2/page2_3/page2_3_3">TextDomain1 2.3.3</a>
+ <ul>
+ <li class="active">
+ <a href="page2/page2_3/page2_3_3/1">TextDomain2 2.3.3.1</a>
+ </li>
+ <li class="active">
+ <a href="page2/page2_3/page2_3_3/2">Page 2.3.3.2</a>
+ </li>
+ </ul>
+ </li>
+ </ul>
+ </li>
+ </ul>
+ </li>
+</ul>
View
118 tests/ZendTest/View/Helper/Navigation/_files/navigation.xml
@@ -209,4 +209,122 @@
</nav_test2>
+ <nav_test3>
+
+ <page1>
+ <label>Page 1</label>
+ <uri>page1</uri>
+ <pages>
+
+ <page1_1>
+ <label>Page 1.1</label>
+ <uri>page1/page1_1</uri>
+ <textdomain>ZendTest_1</textdomain>
+ </page1_1>
+
+ </pages>
+ </page1>
+
+ <page2>
+ <label>Page 2</label>
+ <uri>page2</uri>
+ <textdomain>ZendTest_1</textdomain>
+ <pages>
+
+ <page2_1>
+ <label>Page 2.1</label>
+ <uri>page2/page2_1</uri>
+ </page2_1>
+
+ <page2_2>
+ <label>Page 2.2</label>
+ <uri>page2/page2_2</uri>
+ <pages>
+
+ <page2_2_1>
+ <label>Page 2.2.1</label>
+ <uri>page2/page2_2/page2_2_1</uri>
+ </page2_2_1>
+
+ <page2_2_2>
+ <label>Page 2.2.2</label>
+ <uri>page2/page2_2/page2_2_2</uri>
+ <active>1</active>
+ </page2_2_2>
+
+ </pages>
+ </page2_2>
+
+ <page2_3>
+ <label>Page 2.3</label>
+ <uri>page2/page2_3</uri>
+ <textdomain>ZendTest_No</textdomain>
+ <pages>
+
+ <page2_3_1>
+ <label>Page 2.3.1</label>
+ <uri>page2/page2_3/page2_3_1</uri>
+ </page2_3_1>
+
+ <page2_3_2>
+ <label>Page 2.3.2</label>
+ <uri>page2/page2_3/page2_3_2</uri>
+ <visible>0</visible>
+ <pages>
+
+ <page2_3_2_1>
+ <label>Page 2.3.2.1</label>
+ <uri>page2/page2_3/page2_3_2/1</uri>
+ <active>1</active>
+ </page2_3_2_1>
+
+ <page2_3_2_2>
+ <label>Page 2.3.2.2</label>
+ <uri>page2/page2_3/page2_3_2/2</uri>
+ <active>1</active>
+
+ <pages>
+ <page_2_3_2_2_1>
+ <label>Ignore</label>
+ <uri>#</uri>
+ <active>1</active>
+ </page_2_3_2_2_1>
+ </pages>
+ </page2_3_2_2>
+
+ </pages>
+ </page2_3_2>
+
+ <page2_3_3>
+ <label>Page 2.3.3</label>
+ <uri>page2/page2_3/page2_3_3</uri>
+ <resource>admin_foo</resource>
+ <textdomain>ZendTest_1</textdomain>
+ <pages>
+
+ <page2_3_3_1>
+ <label>Page 2.3.3.1</label>
+ <uri>page2/page2_3/page2_3_3/1</uri>
+ <active>1</active>
+ <textdomain>ZendTest_2</textdomain>
+ </page2_3_3_1>
+
+ <page2_3_3_2>
+ <label>Page 2.3.3.2</label>
+ <uri>page2/page2_3/page2_3_3/2</uri>
+ <resource>guest_foo</resource>
+ <active>1</active>
+ </page2_3_3_2>
+
+ </pages>
+ </page2_3_3>
+
+ </pages>
+ </page2_3>
+
+ </pages>
+ </page2>
+
+ </nav_test3>
+
</navigation_test>
Something went wrong with that request. Please try again.