From 0c9355a8fb06719fc7ae798f1f78d1696d5e9a9c Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 6 Apr 2016 14:49:43 +0200 Subject: [PATCH] [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 --- addons/website/models/ir_http.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index 66df089b933..71aad4bc127 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -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')