[FIX] web,http_routing: correctly invalidate cache translation
cache_hashes was introduced at 8a28cc22fd to reduce the number of reload
The cache is correctly reseted when the translations content changed but did
not contain all the translation-related parameters that are, however, stored
in the session_info
This commit fixes two bugs:
Language parameters invalidation:
1. Access the webclient in a specific language
2. Modify the language parameters (e.g. thousands separator)
3. Refresh the page
--> webclient is still using old language parameters (from cache)
No translation flag after installing a language:
1. Load a database in English in mono-language
2. Load a second language
3. Access a record with a translated field
--> translation button not present on translated field (multi_lang is still
false in cache value)
To fix it, this commit adds all the information that are returns by the
/web/webclient/translations call to make sure the hash represent the reality
closes odoo/odoo#34266
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
@@ -246,12 +246,17 @@ class IrHttp(models.AbstractModel):
|
||||
modules = IrHttpModel.get_translation_frontend_modules()
|
||||
user_context = request.session.get_context() if request.session.uid else {}
|
||||
lang = user_context.get('lang')
|
||||
translations, _ = request.env['ir.translation'].get_translations_for_webclient(modules, lang)
|
||||
translations, lang_params = request.env['ir.translation'].get_translations_for_webclient(modules, lang)
|
||||
translation_cache = {
|
||||
'lang_parameters': lang_params,
|
||||
'modules': translations,
|
||||
'multi_lang': len(request.env['res.lang'].sudo().get_installed()) > 1,
|
||||
}
|
||||
|
||||
session_info.update({
|
||||
'translationURL': '/website/translations/',
|
||||
'cache_hashes': {
|
||||
'translations': hashlib.sha1(json.dumps(translations, sort_keys=True).encode()).hexdigest(),
|
||||
'translations': hashlib.sha1(json.dumps(translation_cache, sort_keys=True).encode()).hexdigest(),
|
||||
},
|
||||
})
|
||||
return session_info
|
||||
|
||||
@@ -32,10 +32,15 @@ class Http(models.AbstractModel):
|
||||
_, qweb_checksum = concat_xml(files)
|
||||
|
||||
lang = user_context.get("lang")
|
||||
translations_per_module, _ = request.env['ir.translation'].get_translations_for_webclient(mods, lang)
|
||||
translations_per_module, lang_params = request.env['ir.translation'].get_translations_for_webclient(mods, lang)
|
||||
translation_cache = {
|
||||
'lang_parameters': lang_params,
|
||||
'modules': translations_per_module,
|
||||
'multi_lang': len(request.env['res.lang'].sudo().get_installed()) > 1,
|
||||
}
|
||||
|
||||
menu_json_utf8 = json.dumps(request.env['ir.ui.menu'].load_menus(request.session.debug), default=ustr, sort_keys=True).encode()
|
||||
translations_json_utf8 = json.dumps(translations_per_module, sort_keys=True).encode()
|
||||
translations_json_utf8 = json.dumps(translation_cache, sort_keys=True).encode()
|
||||
|
||||
return {
|
||||
"uid": request.session.uid,
|
||||
|
||||
Reference in New Issue
Block a user