[IMP] website: use default language for some bots

Currently when using a language on the website, the following is done in
this order to choose which one will be used:

1) use a language code if present in the url (eg. /fr_BE/),
2) use a language similar to the one in the url,
3) use a previously choosed language (saved in cookie),
4) use the browser language if available on website,
5) use a language similar to the browser language,
6) use the default website language

When a bot is requesting a page, he could either not specify a browser
language (en_US is set as default) or sometimes specify english
erroneously.

In these instance, we will then never use the default website language
if an english language is installed.

This fix changes this behaviour so if a bot is visiting a page, the 4th
and 5th steps are skipped and the default website language is used
instead of using the browser language.

closes #14033
opw-690910
This commit is contained in:
Nicolas Lempereur
2016-10-31 13:43:01 +01:00
parent 002d7a342a
commit d05136a0b2
+2 -3
View File
@@ -132,14 +132,13 @@ class ir_http(orm.AbstractModel):
langs = [lg[0] for lg in request.website.get_languages()]
path = request.httprequest.path.split('/')
if first_pass:
is_a_bot = self.is_a_bot()
nearest_lang = not func and self.get_nearest_lang(path[1])
url_lang = nearest_lang and path[1]
preferred_lang = ((cook_lang if cook_lang in langs else False)
or self.get_nearest_lang(request.lang)
or (not is_a_bot and self.get_nearest_lang(request.lang))
or request.website.default_lang_code)
is_a_bot = self.is_a_bot()
request.lang = request.context['lang'] = nearest_lang or preferred_lang
# if lang in url but not the displayed or default language --> change or remove
# or no lang in url, and lang to dispay not the default language --> add lang