I have been using an easier way that seems to work for me and avoids having to use printf everywhere. I made my own TMX translate adapter that extends Zend_Translate_Adapter_Tmx and I overrode the _() function. Here is the class:
Set it in my bootstrap like this:Code:class My_Translate_Adapter_Tmx extends Zend_Translate_Adapter_Tmx { public function _($messageId) { $translation = $this->translate($messageId, $this->getLocale()); if(func_num_args() > 1) { $args = func_get_args(); $args[0] = $translation; $translation = call_user_func_array('sprintf', $args); } return $translation; } }
This allows you to use _() with OR without parameters. For instance, in my TMX file I have these two entries:Code:$translator = new Zend_Translate('My_Translate_Adapter_Tmx', APPLICATION_PATH . '/views/languages/' . $languageStr . '.tmx', $languageStr, $options);
With those I can get the translations like so:Code:<tu tuid="message_permission_denied"> <tuv xml:lang="en_US"><seg>You do not have permission to access this resource.</seg></tuv> </tu> <tu tuid="details_permission_denied"> <tuv xml:lang="en_US"><seg>The user "%1$s" does not have permission to access resource "%2$s".</seg></tuv> </tu>
Hope that helps, let me know if you have any questions.Code:$translator->_('message_permission_denied') $translator->_('details_permission_denied', $user->getUserName(), $reqActionStr)


LinkBack URL
About LinkBacks



Reply With Quote
