Ok, I'll explain a bit precisely.
In my application german (de) is the standard-locale and the german language-file would always be the complete one. for test-reasons, i changed my firefox-language-option to "en", so Zend_Locale retrieves english as the actual locale. but it's not completly translated.
so i wanted to reroute "en" to "de" if the identifiers aren't found in the "en"-languagefile.
...
;----------------------------
; Zend_Locale
;----------------------------
resources.locale.default = "de"
;----------------------------
; Zend_Translate
;----------------------------
resources.translate.adapter = "Tacticx_Translate_Adapter_Gettext"
resources.translate.data = APPLICATION_PATH "/languages"
resources.translate.default = "de"
resources.translate.locale = "auto"
resources.translate.route.en = "de"
resources.translate.options.disableNotices = false
resources.translate.options.logUntranslated = true
resources.translate.options.scan = "directory"
resources.translate.options.ignore[] = "."
resources.translate.options.ignore.regex = "/\.po$/i"
...
protected function _initTranslation()
{
$this->bootstrap('locale');
$this->bootstrap('translate');
$translate = Zend_Registry::get('Zend_Translate');
$writer = new Zend_Log_Writer_Stream(APPLICATION_ROOT_PATH
. '/data/logs/translation.log');
$log = new Zend_Log($writer);
$translate->setOptions(array('log' => $log));
}
protected function _initNavigationMenu()
{
$this->bootstrap('locale');
$this->bootstrap('translate');
$this->bootstrap('translation');
require_once(APPLICATION_ROOT_PATH . DIRECTORY_SEPARATOR . 'data'
. DIRECTORY_SEPARATOR . 'menu' . DIRECTORY_SEPARATOR
. 'menu.inc.php');
Zend_Registry::set('Zend_Navigation', $menu);
$menu = new Zend_Navigation(
array(
array(
'label' => 'navigation::home',
'uri' => '/',
'pages' => array(
array(
'label' => 'navigation::login',
'controller' => 'access',
),
array(
'label' => 'navigation::logout',
'action' => 'logout',
'controller' => 'access',
)
),
),
array(
'label' => 'navigation::organization_editor',
'module' => 'mgr',
'action' => 'index',
'controller' => 'organization',
),
...
as you can see, the navigation labels are "identifiers", which should be translated by Zend_Translate.
The Zend_View_Helper_SOMETHING
is used to create the menu-structure and there the labels got translated.
In that example the View_Helper_???... (i'm @home at the moment and can't say, which is used. tomorrow i'll again debug that and add that information) gets the Translator (I expect Zend_Translate from Zend_Registry) and calls ->translate("navigation::login");
locale is null and gets the currently user-locale (line 656, Zend/Translate/Adapter.php).
the next lines until line 707 are skipped, because the conditions don't match.
after that, because of missing languagefile-entries in the english-language-file, the next lines are skipped (conditions don't match) until line 735/736:
$this->_log($messageId, $locale);
then we come to the routing-part (lines 737 - 745):
if (!empty($this->_options['route'])) { if (array_key_exists($locale, $this->_options['route']) && !array_key_exists($locale, $this->_routed)) { $this->_routed[$locale] = true; return $this->translate($messageId, $this->_options['route'][$locale]); }
$this->_routed = array(); }
in that navigation-menu, the next identifier also isn't translated in the english-language-file.
so we are in the same helper and have the same translator-object (TO1), which "$this->_routed[$locale]" value is still not resetted (I debugged that!!!). so: $this->_routed["en"] is true.
the view helper now calls with that translator (TO1) ->translate("the_next_identifier");
as before no line matches one of the if-conditions and we come to lines 737 - 745:
if (!empty($this->_options['route'])) { if (array_key_exists($locale, $this->_options['route']) && !array_key_exists($locale, $this->_routed)) { $this->_routed[$locale] = true;
return $this->translate($messageId, $this->_options['route'][$locale]);
}
$this->_routed = array(); }
the reason is, that the reset:
$this->_routed = array();
is only resetted on three positions:
line 53, on initialization: private $_routed = array();
line 689, $this->_routed = array(); after Zend_Locale::isLocale-checks
line 744, $this->_routed = array(); after rerouting
more specific code-examples I can only support from work tomorrow.
what code examples do you need?
best regards,
rené
The code works as expected. It would be nice if you give a real example instead of framework code.
This is a simple recursive methodcall as used in many other components and projects. When you follow the workflow you would see that _route is resetted before the rerouted translation is returned.
I can't see a failure wether in code nor within the testbed which tests the code.