ZF-10948: option to disable translation of labels in zend navigation


Zend_Navigation always translates labels and titles for the container.

There is an option in the view helper to disable the translation for the whole container, but there is no option to disable this translation for specific pages.

Example use case:

$page = new Zend_Navigation_Page_Mvc(}}
        'label' => $blogPost->alreadyTranslatedTitleFromDb
        // ... 

$page2 = new Zend_Navigation_Page_Mvc(
        'title' => 'Edit: ' . $blogPost->alreadyTranslatedTitleFromDb
        // ... 


Now, when I use:




the label is translated twice. The same for breadcrumbs, sitemaps etc.

Translation logs are filled with ~random messages.

Option to disable the translation is needed:

$page = new Zend_Navigation_Page_Mvc(
        'label' => $blogPost->alreadyTranslatedTitleFromDb
        'disableTranslation' => true
        // ... 


This is not a bug, because the Zend_Navigation - view helpers translate the label and title only once! I think this is more of a suggestion for an improvement. Please change the type of these issue and remove it as an affected component Zend_Translate.

Can you write a few tests and a patch? That would be very useful for quick editing. Thanks.

Changed priority to major, because the patch with unit tests is available and can be easily fixed.

I wrote a fix for this issue, including unit tests. The fix is backwards compatible.

Here is link to the patch and modified files:… (how can I upload it here? Could someone do this?)

This basically adds useTranslator property with getter and setter, and some conditions in view helpers handling the new option.

The patch contains new methods for the unit tests and the modifications to the library itself.

List of modified files.

Modified: library/Zend/Navigation/Container.php Modified: library/Zend/Navigation/Page.php Modified: library/Zend/View/Helper/Navigation/Breadcrumbs.php Modified: library/Zend/View/Helper/Navigation/HelperAbstract.php Modified: library/Zend/View/Helper/Navigation/Menu.php

Unit Tests:

Modified: tests/Zend/Navigation/ContainerTest.php Modified: tests/Zend/Navigation/PageTest.php Modified: tests/Zend/View/Helper/Navigation/BreadcrumbsTest.php Modified: tests/Zend/View/Helper/Navigation/MenuTest.php Modified: tests/Zend/View/Helper/Navigation/NavigationTest.php Added: tests/Zend/View/Helper/Navigation/_files/expected/menu/translated_one_page_without_translator.html


Hi Tomek, why the container must be changed?


When you want to add a page, which is already translated, currently there's no option to disable translation just for this particular page container on the pre-view helper level (without iteration).

Patch and unit tests from Tomek added.