Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translations (MO): Contextual translation can override non-contextual one #26168

Closed
cogk opened this issue Apr 25, 2024 · 2 comments · Fixed by #26429
Closed

Translations (MO): Contextual translation can override non-contextual one #26168

cogk opened this issue Apr 25, 2024 · 2 comments · Fixed by #26429
Assignees

Comments

@cogk
Copy link
Contributor

cogk commented Apr 25, 2024

(low-priority bug /cc @barredterra)

Explanation

This bug is introduced when catalogs are merged across applications, because of the following lines:

if m.id not in translations:
# better a translation with context than no translation
translations[m.id] = m.string

Because intermediary dicts (1 per app) are merged in order, then a later de-contextualized translation (= a fallback) can overwrite a non-contextual one, which should be of a higher priority.

frappe/frappe/translate.py

Lines 176 to 178 in 9e8808f

for app in apps or frappe.get_installed_apps(_ensure_on_bench=True):
translations.update(get_translations_from_csv(lang, app) or {})
translations.update(get_translations_from_mo(lang, app) or {})

Example

The following PO files of two different applications:

# app1.po
# no context
msgid   "FROM"
msgstr  "From"
# app2.po
msgctxt "Communication"
msgid   "FROM"
msgstr  "Communication sent by"

Will be converted to these two dicts:

app1_translations = {
  "FROM": "From",
}

app2_translations = {
  "FROM": "Communication sent by",  # 🚨 this is the bug
  "FROM:Communication": "Communication sent by",
}

Which, when merged in order, won't produce the expected result.

Expected

_("FROM")  # -> From
_("FROM", context="Communication")  # -> Communication sent by

Actual

_("FROM")  # -> Communication sent by
_("FROM", context="Communication")  # -> Communication sent by
@barredterra
Copy link
Collaborator

Is it enough to just remove these three lines?

@cogk
Copy link
Contributor Author

cogk commented Apr 25, 2024

I haven't checked yet, but I believe removing them would fix the bug 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants