Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#4979 from shadowdani/n…
Browse files Browse the repository at this point in the history
…av-textdomain

Add multiple translation text domains to Zend\Navigation
  • Loading branch information
weierophinney committed Aug 19, 2013
149 parents f2a1815 + c60cca9 + 76c4d1c + 83cbc8a + 1b9fd60 + 8a8b989 + 10da323 + e6aba5a + b71d0a2 + 2aa926c + 8405746 + bf1a8de + f16339d + ed1dbc8 + dbf56da + bdb277e + 364ced3 + 9fccdf3 + 40f5963 + 9d7ddea + e1e4aa8 + 870703b + 958decf + e49a08e + a051e7e + b9f6e35 + 2bbef72 + aea30ce + faec0a2 + 098e166 + 51d6372 + 8757ace + 42477b6 + 32cf329 + 0ebadc5 + 188fa4d + a41bbf0 + a29bbbc + 941280d + d691226 + e547023 + d91c234 + 006ef75 + 69d1518 + 7dc0d1a + a995715 + e780008 + e810876 + 9e4090a + 269bf01 + 3a1f2fd + 0cab32d + 704cc7f + e20c9e6 + a0dfc1a + 76b3e1c + fd429e8 + 187ea79 + 2b43ea6 + e3b1be1 + 19f0ef6 + 33bf9c0 + 3729984 + a5ce396 + 698dbe0 + 0efca0b + 08b2a78 + ddaa846 + 7fe4493 + 0da7331 + 7226b1d + 851904c + a2eb795 + f658a03 + de83270 + 806df8a + 4e7ff23 + 409b768 + 1b97191 + d2649e3 + f0162d1 + 6f01416 + a2b3753 + 1786961 + d157fcb + 4444c37 + 192d20c + 811122b + 3a2cf9b + eb2029b + 7a6edab + 8d8a05d + c1ddf21 + 0090b4d + ef80e35 + 59b30de + 4656098 + 377b920 + ccba82c + 5d2770e + 41714a1 + 8adef43 + a78628f + b35fa7a + 3953c79 + aa28e42 + 38f9a49 + 47ed633 + 0a6bf6e + b61d89d + a1fbb6f + 238512b + f40a328 + 62dc143 + 328df3b + e12fe2d + e34a942 + 04e956d + a19a8c2 + ac4b6c0 + d28282e + bd5af3d + b976cb5 + 4feb67b + 7164be7 + 40174df + e4918ae + 1d9f9a2 + c77ae57 + 223b881 + c2f4e25 + e08b166 + e58e548 + 85e6bbd + 0ac2052 + c7ba6af + f443c57 + 1380626 + 5316b6e + a6136d4 + d233be3 + c100a2a + c6a0e2c + e7eef3c + 812f35d + 604cdcd + 5472285 + 6e2f420 + 77fce7b commit 4f66433
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Helper/Navigation/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Helper/Navigation/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
43 changes: 43 additions & 0 deletions test/Helper/Navigation/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ abstract class AbstractTest extends \PHPUnit_Framework_TestCase
*/
protected $_nav2;

/**
* The third container in the config file (files/navigation.xml)
*
* @var Navigation\Navigation
*/
protected $_nav3;

private $_oldControllerDir;

/**
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
9 changes: 9 additions & 0 deletions test/Helper/Navigation/BreadcrumbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions test/Helper/Navigation/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/Helper/Navigation/_files/expected/bc/textdomain.html
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions test/Helper/Navigation/_files/expected/menu/textdomain.html
Original file line number Diff line number Diff line change
@@ -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>
118 changes: 118 additions & 0 deletions test/Helper/Navigation/_files/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 4f66433

Please sign in to comment.