From f4d57527248e290f8c596e97047a876ec30e3c23 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 15 May 2023 12:42:14 +0000 Subject: [PATCH] [IMP] tools: load also es_MX The translations on Spanish (Mexico) are more active than on Spanish Moreover, most other countries speaking a variant of Spanish are located in Latin America and are closer to es_MX than es. To solve this, when installing for instance es_AR, the translations will be loaded in the following order: 1 es 2 es_MX 3 es_AR In case a term is translated in both es and es_MX (and not es_AR), the later will be used closes odoo/odoo#121415 Signed-off-by: Martin Trigaux (mat) --- addons/mail/models/template_reset_mixin.py | 6 ++++++ odoo/addons/base/models/ir_module.py | 6 ++++++ odoo/tools/translate.py | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/addons/mail/models/template_reset_mixin.py b/addons/mail/models/template_reset_mixin.py index 9f211e8ed56..f37756a0b23 100644 --- a/addons/mail/models/template_reset_mixin.py +++ b/addons/mail/models/template_reset_mixin.py @@ -74,6 +74,12 @@ class TemplateResetMixin(models.AbstractModel): if base_trans_file: translation_importer.load_file(base_trans_file, code, xmlids=xml_ids) + # Step 1.5: in case of latin america Spanish variation, load es_MX too + if base_lang_code == "es" and lang_code != "es_MX": + mx_trans_file = get_module_resource(module_name, 'i18n', 'es_MX.po') + if mx_trans_file: + translation_importer.load_file(mx_trans_file, code, xmlids=xml_ids) + # Step 2: reset translation file with main language file (can possibly override the # terms coming from the base language) trans_file = get_module_resource(module_name, 'i18n', lang_code + '.po') diff --git a/odoo/addons/base/models/ir_module.py b/odoo/addons/base/models/ir_module.py index 0442554cf10..2408e2225e9 100644 --- a/odoo/addons/base/models/ir_module.py +++ b/odoo/addons/base/models/ir_module.py @@ -942,6 +942,12 @@ class Module(models.Model): _logger.info('module %s: loading base translation file %s for language %s', module_name, base_lang_code, lang) translation_importer.load_file(base_trans_file, lang) + if base_lang_code == "es" and lang != "es_MX": + mx_trans_file = get_module_resource(module_name, 'i18n', 'es_MX.po') + if mx_trans_file: + _logger.info('module %s: loading translation file %s for language %s', module_name, "es_MX", lang) + translation_importer.load_file(mx_trans_file, lang) + # i18n_extra folder is for additional translations handle manually (eg: for l10n_be) base_trans_extra_file = get_module_resource(module_name, 'i18n_extra', base_lang_code + '.po') if base_trans_extra_file: diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index b88854c9ac5..454015369cb 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -1479,6 +1479,12 @@ class CodeTranslations: get_resource_path(mod, 'i18n', lang + '.po'), get_resource_path(mod, 'i18n_extra', lang_base + '.po'), get_resource_path(mod, 'i18n_extra', lang + '.po')] + if lang_base == "es" and lang != "es_MX": + # force es_MX as fallback language for the different spanish + # es_MX is more actively translated and closer to many languages + po_paths = [po_paths[0]] + [get_resource_path(mod, 'i18n', 'es_MX.po')] + \ + po_paths[1:3] + [get_resource_path(mod, 'i18n_extra', 'es_MX.po')] + \ + [po_paths[3]] return [path for path in po_paths if path] @staticmethod