From 2ba7fa3c9d439097866e23f7decd1411e4d88ffc Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 29 Feb 2016 17:38:27 +0100 Subject: [PATCH] [FIX] website: alternate languages translated URL The alternate languages links set in the page `` were not translated in each language, but within the language the user is browsing the website. This leaded to SEO referencing issues, as these links leaded to (30x) redirections if followed, to translate the URL slug within the new current language. e.g. `/fr_FR/shop/product/bose-mini-bluetooth-speaker-7` automatically redirected to `/fr_FR/shop/product/mini-haut-parleur-bluetooth-bose-7` And it was the first link which was displayed as alternate link when being in another language than French, while it should be the second (to avoid the useless redirection). opw-669979 --- addons/website/models/website.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 1d5ffd26f7d..180eee13144 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -241,14 +241,22 @@ class website(osv.osv): if req is None: req = request.httprequest default = self.get_current_website(cr, uid, context=context).default_lang_code - uri = req.path - if req.query_string: - uri += '?' + req.query_string shorts = [] + + def get_url_localized(router, lang): + arguments = dict(request.endpoint_arguments) + for k, v in arguments.items(): + if isinstance(v, orm.browse_record): + arguments[k] = v.with_context(lang=lang) + return router.build(request.endpoint, arguments) + router = request.httprequest.app.get_db_router(request.db).bind('') for code, name in self.get_languages(cr, uid, ids, context=context): lg_path = ('/' + code) if code != default else '' lg = code.split('_') shorts.append(lg[0]) + uri = request.endpoint and get_url_localized(router, code) or request.httprequest.path + if req.query_string: + uri += '?' + req.query_string lang = { 'hreflang': ('-'.join(lg)).lower(), 'short': lg[0],