You're right, it's not fully solved yet. But with the locales array
you pass to getPreferredLanguage(...), you can help yourself if we
decide that it is too overhead for the core. Usually translations in a
project have only language codes instead of full locales (f.e. "de",
"tr", "fr", "en"). The user's preference can have locales like
"de_DE", "de_CH" or "fr_CH". So the array_intersect of both arrays
won't have the expected answer. It could happen that there is no match
and Symfony2 would select the first entry of the locales you passed to
the method. If the user has "de_DE", "en" as preferred language.
Symfony2 would return "en" if the locales are "de" and "en". So I
think we need additional logic here.

I think I understood the question at the conference right. If we take
Switzerland as an example. German, French and Italian are official
languages. If I have set "de_CH", "fr_CH" and "it_CH" as my preferred
order and we have translation "de", "fr_FR" and "it", I would be more
happy about getting "de" instead of "fr_FR". Although I have set
French as my second choice, general German as "Swiss German"
replacement has more weight than French.

Yes I agree. Usually the preferred language functionality is more for
the first visit of a user. In my projects I have a language selector
and I save the culture in user's session (to go through the language
detection only once) or if there is a persistant profile, I save it
there (account settings). So account setting or session has more
weight than language detection.

If they are built-in browsers like IE or Safari language settings are
already set for the country in which the computer is offered for sale.
Downloaded browsers (f.e. Firefox) have the default culture for the
version you download (German Firefox will have de_DE and de already
configured). I don't know how it is in Switzerland.

Browsers save the locale not in underscore notation but hyphen
notation. de_DE is de-DE.

On 9 Okt., 18:43, Lukas Kahwe Smith <[email protected]> wrote:
> On 09.10.2010, at 13:30, Fabien Potencier wrote:
>
>
>
>
>
> >> Does Symfony2 read the user's preferred languages from browser? In
> >> Zend Framework I can tell ZF to read the browser preference:
>
> >> $translate = new Zend_Translate(
> >>    'gettext',
> >>    APPLICATION_PATH . '/langs',
> >>    $locale->getLanguage(),
> >>    array(
> >>        'scan'           =>  Zend_Translate::LOCALE_FILENAME,
> >>        'disableNotices' =>  true
> >>    )
> >> );
>
> >> $locale->getLanguage() parses the $_SERVER['HTTP_ACCEPT_LANGUAGE']
>
> > In Symfony2, $request->getPreferredLanguage($arrayOfSupportedLanguages);
>
> great.
>
> @halk: but again this doesnt solve the issue.
>
> "F.e. if "de_DE", "tr_TR" and "en_GB" are the preferred languages set
> in the user's browser, Symfony2 should first look for the translations
> "de_DE", then "de". If still no match, it should try to find a
> translation catalogue for the next preferred language, in this case
> "tr_TR" and if not "tr" etc. If non of the preferred languages
> matches, Symfony2 will take the culture defined in configuration."
>
> the above is simply not possible with the current system, because if a 
> translation was missing in "de_De" it would have set the translation for the 
> term to be either "de" or if there is none for "de" the default language 
> (f.e. "en"). So in other words if there is no way for you to figure out that 
> there is a translation in "en" but none in "de" and "de_DE".
>
> for this you would either need to write a totally different solution for the 
> fallback handling or you would beed to go in the direction i explained where 
> you would do the normal fallback logic just for all relevant fallback orders 
> (f.e. "de_DE", "de", "de_CH", "fr", "en" ..) which would essentially be 
> stored as some pseudo language and you would always try to map an actual 
> users preferred language order to one of these pseudo languages.
>
> again the clarify the use case that was asking Fabien at the conference:
> in multi lingual countries its common for people to speak some or even all of 
> the languages, but they have custom preferences. i think few people actually 
> take the time to configure their preferences in the browser. however 
> especially for intranet apps i have seen a few where the user could set 
> things in their profile (though educating them to use the browser settings 
> might make more sense, though this then obviously ties the setting to the 
> browser and therefore a given computer rather than a user in the intranet). 
> obviously in this case, aka the language preference order being part of the 
> intranet user profile, then that would need to be read from some data source 
> and passed to symfony2 rather than being able to be deduced from the browser 
> settings.
>
> regards,
> Lukas Kahwe Smith
> [email protected]

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to