[FIX] website: prefer to get exact language

request.website.get_languages returns a list of tuple in the form:

        (`language code`, `language name`)

With this commit the code first check if there is a language exactly
matching, and only if failed check if there is a match on the short
form.

closes #11613
opw-672412
This commit is contained in:
Nicolas Lempereur 2016-04-06 14:49:43 +02:00
parent b6386a0a7e
commit 0c9355a8fb
No known key found for this signature in database
GPG Key ID: F63F7EEB0B3CFC48
1 changed files with 7 additions and 7 deletions

View File

@ -55,14 +55,14 @@ class ir_http(orm.AbstractModel):
def get_nearest_lang(self, lang):
# Try to find a similar lang. Eg: fr_BE and fr_FR
if lang in request.website.get_languages():
return lang
short = lang.split('_')[0]
short = lang.partition('_')[0]
short_match = False
for code, name in request.website.get_languages():
if code.startswith(short):
return code
return False
if code == lang:
return lang
if not short_match and code.startswith(short):
short_match = code
return short_match
def _dispatch(self):
first_pass = not hasattr(request, 'website')