Translation with Zend Translate only works in OSX Firefox, no others browsers -
my translation set-up works (i mean, fine :) ) in firefox on osx. on other browser translation stay in french, default language.
i var_dump in view:
var_dump($this->translate('envoyer')): string 'send' (length=4) var_dump($this->translate()->getlocale()): string 'en' (length=2)
here init_translate in bootstrap.php:
public function _inittranslate() { zend_loader::loadclass('zend_translate'); zend_loader::loadclass('zend_registry'); //////////////////////////// // validator messages translation $language = 'fr'; // on définit le traducteur à utiliser $translate = new zend_translate( array( 'adapter' => 'array', 'content' => application_path . '/../resources/languages', 'locale' => $language, 'scan' => zend_translate::locale_directory )); // apply on validation messages : zend_validate_abstract::setdefaulttranslator($translate); /////////////////////////// // site translation // current registry $registry = zend_registry::getinstance(); /** * set application wide source locale * source string language; * i.e. $this->translate('hi english string'); */ $locale = new zend_locale('fr_ca'); zend_registry::set('zend_locale', $locale); $session = new zend_session_namespace('session'); //$langlocale = isset($session->lang) ? $session->lang : $locale; //$langlocale = $locale; /** * set , load translations (all of them!) * resources.translate.options.disablenotices = true * resources.translate.options.loguntranslated = true */ $translate = new zend_translate('gettext', application_path . directory_separator .'languages', 'auto', array( 'disablenotices' => true, // idea! 'loguntranslated' => false, // change if debug ) ); /** * both of these registry keys magical , makes * zf 1.7+ automagical things. */ $registry->set('zend_locale', $locale); $registry->set('zend_translate', $translate); return $registry; }
my language switcher plugin (author: danny froberg ):
class my_controller_plugin_langselector extends zend_controller_plugin_abstract { public function predispatch(zend_controller_request_abstract $request) { $registry = zend_registry::getinstance(); // our translate object registry. $translate = $registry->get('zend_translate'); $currlocale = $translate->getlocale(); // create session block , save locale $session = new zend_session_namespace('session'); $lang = $request->getparam('lang',''); // register "approved" locales below. switch($lang) { case "fr": $langlocale = 'fr_ca'; break; case "en": $langlocale = 'en_ca'; break; default: /** * set locale session or set * current application wide locale (set in * bootstrap)if not. */ //$langlocale = isset($session->lang) ? $session->lang: $currlocale; $langlocale = 'fr_ca'; break; } $newlocale = new zend_locale(); $newlocale->setlocale($langlocale); $registry->set('zend_locale', $newlocale); $translate->setlocale($langlocale); $session->lang = $langlocale; // save modified translate registry $registry->set('zend_translate', $translate); } }
and selector in view:
<a href="#" onclick="dopostlang(this.href, 'fr');">fr</a> <a href="#" onclick="dopostlang(this.href, 'en');">en</a>
the javascript job (the var_dump show actual locale; "fr" when "fr" clicked , "en" when "en" clicked), dont understand why i'm facing browser issue?
i'm lost, if may @ , point me direction go please, i'll appreciate.
thanks,
yahoo! self-resolved! (but dont know why) :)
but if else fall in same dummer trap :)
first of enable translate notice in .config file:
resources.translate.options.disablenotices = false resources.translate.options.loguntranslated = false
secondo, follow official guide first try else. mysterious reason, lines cause problem:
$translate = new zend_translate('gettext', application_path . directory_separator .'languages', 'auto', array( 'disablenotices' => false, // idea! 'loguntranslated' => true, // change if debug ) );
i replaced lines (from offical doc: http://framework.zend.com/manual/1.12/en/zend.translate.using.html):
$translate = new zend_translate( array( 'adapter' => 'gettext', 'content' => application_path . directory_separator .'languages/fr_ca.mo', 'locale' => 'fr' ) ); $translate->addtranslation( array( 'content' => application_path . directory_separator .'languages/en_ca.mo', 'locale' => 'en' ) );
thanks :)
Comments
Post a Comment