I would say that example and text do not fit.
For the old API you simply have to check if the language is available (isAvailable) and if not set the wished language manually.

Something like
if ($translate->isAvailable($locale->getLocale())) {
  $translate->setLocale($locale->getLocale());
} else {
  $translate->setLocale('en');
}

The new API allows setting a language which does not exist.

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 1:38 PM
Subject: Re: [fw-general] Zend_Translate automatic language detection


Hi, Thomas,

thanks for your ultra-quick reply.

Why do the examples use no auto detection? The manual says: "as long as
you only add new translation sources with the |addTranslation()| method
|Zend_Translate| will automatically set the best fitting language for
your environment. So normally you will not need to call |setLocale()|."
Doesn't that sound, as if Zend_Translate is using automatic detection as
a default?

Furthermore the manual says "After setting a language manually with the
|setLocale()| method the automatically detection will be switched
off...". For me, that says: if you do NOT use setLocale(), it is set to
'auto' by default.


The whole manual part (except the example) reads like this:


       46.3.8.1. Automatically handling of languages

Note that as long as you only add new translation sources with the
|addTranslation()| method |Zend_Translate| will automatically set the
best fitting language for your environment. So normally you will not
need to call |setLocale()|.

The algorithmus will search for the best fitting locale depending on the
users browser and your environment. See the following example for details:

[... Example here ...]

After setting a language manually with the |setLocale()| method the
automatically detection will be switched off and overridden.

If you want to use the automatic again, you can set the language *auto*
with |setLocale()| which will reactivate the automatically detection for
|Zend_Translate|.


Best regards,
Jörg


Thomas Weidner schrieb:
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


Reply via email to