nuxeo-localizer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nuxeo-localizer] user prefered language


From: Juan David Ibáñez Palomar
Subject: Re: [Nuxeo-localizer] user prefered language
Date: Mon, 18 Nov 2002 09:45:29 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020913 Debian/1.1-1

Olivier Nibart wrote:

Hi all,

First of all, I hope I'm not boring you with the same-newbie-question, but I
didn't find any answer in the archives.

I want the first language shown on a web page to be the user prefered one.

But I found that it works well only if the langages list set at browser
level is set with only one language.
For example, with a default language set on Localizer as EN, if I set my
browser with FR as the first language, and EN as the second one, Localizer
will use EN.

I found that all the qualities of the languages in the AcceptLanguage
instance where set to 1.0, thus loosing the user prefs sorting.
I wanted also any complex language (ie fr-be or en-us) to be simplified (fr
or en), but this is specific as others may want to go to that level of
localisation.

Are you sure you want to remove the "complex" languages?

Imagine that you set a language en your server as "fr", it
doesn't matters wether somebody visits the web site with fr,
with fr-fr or with fr-be, all they will work and the user
will see "fr".


So I made a script, added to the accept_method list, wich I give you for
comments or suggestions (I'm also new to python...) :

-----------------------------------
import string


You don't really need to import "string", since Python 2 the string
functions are included as method of the string objects. And, by the
way, it isn't used in the code.


request = container.REQUEST

user_languages = accept_language.parse(request['HTTP_ACCEPT_LANGUAGE'])


The problem here is that the parse method implements the standard,
but not all browsers do, for example Netscape 4.

Localizer includes code (in __init__.py) that detects NS 4 and
transforms the accept_language string to a standard one.

This could explain why you see all qualities set to one.


available_languages = container.get_available_languages()
default_languages = container.get_default_language()

# clean up language ID (ie fr-be or nl-be)

for lang in user_languages.keys():
 if (len(lang) > 2) and (lang[2] == '-'):
   clean_lang = lang[:2]
   user_languages[clean_lang] = user_languages[lang]
   del user_languages[lang]

# choose the lang to use
# - if q > 1.0 (via accept_path or accept_cookies), use that q
# - if q<= 1.0 use q found in HTTP_ACCEPT_LANGUAGE

language, quality = None, 0.0
for lang in available_languages:
 q = accept_language.get_quality(lang)
 if (q <= 1.0) and (user_languages.has_key(lang)):
   q = user_languages[lang]  if q > quality:
   language, quality = lang, q


I think this piece of code is not well formatted, the expression
"user_languages[lang]  if q > quality" will raise a syntax error.


# if a lang as been determined, set it's q to 4.0 to be sure it'll be the
one used

if language != None:
 accept_language.set(language, 4.0)

# set SELECTED_LANGUAGE, as we use it later
selected_language = container.get_selected_language()
request.set('SELECTED_LANGUAGE', selected_language)
-----------------------------------

Did I miss something, or was it the right to do it ?


See the comments inline and send me a new version if you want.

But I would seriously reconsider the removal of the "complex"
languages (fr-fr, fr-be, etc..), you don't win anything, it
will work the same if you leave it as it is.

There are several bugs, but all them will go away if you keep
the "complex" languages.


Anyway, at least for non-US people, this product is **very** valuable,
thanks a lot David !

Olivier Nibart
Amtoys - Belgium



Regards,

--
J. David Ibáñez, http://www.j-david.net
Software Engineer / Ingénieur Logiciel / Ingeniero de Software






reply via email to

[Prev in Thread] Current Thread [Next in Thread]