[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) <mat@odoo.com>
This commit is contained in:
Martin Trigaux
2023-07-28 17:53:53 +02:00
parent 58352b6e69
commit f4d5752724
3 changed files with 18 additions and 0 deletions
@@ -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')
+6
View File
@@ -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:
+6
View File
@@ -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