Jörg,
You set the language manually within Zend_Translate in all examples and
don't use automatic language detection at all.
If you want detection you should set the locale (setLocale) to "browser"
when you only want browser locales, or "auto" if you need a complete
automatic detection.
Autodetection works best when you combine it with scanning.
Given your examples, all seems to work like expected/coded.
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
----- Original Message ----- From: "Jörg Hambuch" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, November 05, 2008 12:46 PM
Subject: [fw-general] Zend_Translate automatic language detection
Hello,
after one and a half days of reading manual and forums, and testing many
configuartions, I dare to ask the mailing list now.
If I take the source code from the manual
(http://framework.zend.com/manual/en/zend.translate.using.html, 46.9.),
it
does not act like described there.
- The output in my browser is the following:
de_AT=1;fr=1;en_US=0.8
it_IT: italiano
it_IT: italiano
de: deutsch
de: deutsch
- After what the manual says, I would have expected that:
de_AT=1;fr=1;en_US=0.8
: key
en: english
de: deutsch
it_IT: italiano
- In my bootstrap, there is nothing about Zend_Translate or Zend_locale
at
all. For testing purposes I just put the code from the manual into my
IndexController.
- My browser (firefox) is set to accept de_AT, fr, en_US.
- I put the neccessary translation files (PHP arrays) in APPLICATION_PATH
.
'/../translations/' and named them it.php, ru.php, en.php es.php and
de.php.
They look like this:
<?php
return array(
'key' => 'english'
);
-My IndexController contains the code from the manual plus a few echo's
from
me. Here it is:
// Let's expect the browser returns this language settings
// HTTP_ACCEPT_LANGUAGE = "de_AT=1;fr=1;en_US=0.8";
echo $_SERVER['HTTP_ACCEPT_LANGUAGE'] . '<br />';
// Example 1:
$translate = new Zend_Translate("gettext", "\my_it.mo", "it_IT");
$translate->addTranslation("\my_es.mo","es_UG");
// no fitting language found, return the messageid
echo $translate->getLocale() . ': ';
echo $translate->_('key') . '<br />';
// Example 2:
$translate = new Zend_Translate("gettext", "\my_en.mo", "en_US");
$translate->addTranslation("\my_it.mo","it_IT");
// best found fitting language is "en_US"
echo $translate->getLocale() . ': ';
echo $translate->_('key') . '<br />';
// Example 3:
$translate = new Zend_Translate("gettext", "\my_it.mo", "it_IT");
$translate->addTranslation("\my_de.mo","de");
// best found fitting language is "de" because "de_AT" will be
// degraded to "de"
echo $translate->getLocale() . ': ';
echo $translate->_('key') . '<br />';
// Example 4:
$translate = new Zend_Translate("gettext", "\my_it.mo", "it_IT");
$translate->addTranslation("\my_ru.mo","ru");
$translate->setLocale("it_IT");
$translate->addTranslation("\my_de.mo","de");
// returns "it_IT" as translation source
echo $translate->getLocale() . ': ';
echo $translate->_('key') . '<br />';
I use Zend Framework 1.6.2, PHP 5.2.6 on Ubuntu with LAMPP.
Could anyone please tell me, what is the problem here?
Best regards,
Jörg Hambuch