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

False Positive: "Duplicate PO message definition" for Contextually Different Translations #122

Closed
Ahmed-Maghraoui-Eezee-It opened this issue Jan 29, 2025 · 10 comments · Fixed by #123
Labels
bug Something isn't working

Comments

@Ahmed-Maghraoui-Eezee-It

Module

hook id: oca-checks-po

Describe the bug

The Odoo pre-commit hook for .po[t] files incorrectly flags valid translations as duplicates when they have different msgstr values.

To Reproduce

Create a .po file with multiple translations for the same msgid, each with different msgstr values.

e.g :

Translation 1

msgid "Submitted"
msgstr "Soumis"

Translation 2

msgid "Submitted"
msgstr "Soumise"

Expected behavior
The pre-commit hook should not flag different msgstr values for the same msgid as duplicates when they represent valid translations in different contexts.

@Ahmed-Maghraoui-Eezee-It Ahmed-Maghraoui-Eezee-It added the bug Something isn't working label Jan 29, 2025
@luisg123v
Copy link

I think the described behavior is expected, because Odoo doesn't support providing different translations for the same term. In fact, if the translation file is re-exported, those will be lost and a single one will be included.

@moylop260
Copy link
Collaborator

@Ahmed-Maghraoui-Eezee-It

Could you export the PO file in order to double-confirm that Luis said, please?

@Ahmed-Maghraoui-Eezee-It
Copy link
Author

@moylop260 @luisg123v
it's not the same term, the first translation is related to a view in the current custom module, and the second is related to a selection field in a standard module.
The translations are working fine and when I export the po file for each module I get different translations as expected.

@moylop260
Copy link
Collaborator

Could you share the po file and the odoo version, please?

@Ahmed-Maghraoui-Eezee-It
Copy link
Author

odoo version 18

fr_BE.po.txt

@moylop260
Copy link
Collaborator

moylop260 commented Jan 30, 2025

I have created a video with the following steps:

  1. Export po file for Spanish for 2 modules (e.g. sale_management, account)
  2. Open the po file and split the "active" msgid in 2 msgstr for different modules similar your example
...

-- ORIGINAL
#. modules: account, sale_management
#: model:ir.model.fields,field_description:account.field_account_account_tag__active
#: model:ir.model.fields,field_description:sale_management.field_sale_order_template__active
#: model:ir.model.fields.selection,name:account.selection__account_lock_exception__state__active
#: model_terms:ir.ui.view,arch_db:account.view_account_tax_search
msgid "Active"
msgstr "Activo"

...
-- EDITED
#. modules: account
#: model:ir.model.fields,field_description:account.field_account_account_tag__active
#: model:ir.model.fields.selection,name:account.selection__account_lock_exception__state__active
#: model_terms:ir.ui.view,arch_db:account.view_account_tax_search
msgid "Active"
msgstr "Activo1"

#. modules: sale_management
#: model:ir.model.fields,field_description:sale_management.field_sale_order_template__active
msgid "Active"
msgstr "Activo2"

The diff

--- original
+++ edited
@@ -1,11 +1,11 @@
-...
-
-#. modules: account, sale_management
+#. modules: account
 #: model:ir.model.fields,field_description:account.field_account_account_tag__active
-#: model:ir.model.fields,field_description:sale_management.field_sale_order_template__active
 #: model:ir.model.fields.selection,name:account.selection__account_lock_exception__state__active
 #: model_terms:ir.ui.view,arch_db:account.view_account_tax_search
 msgid "Active"
-msgstr "Activo"
+msgstr "Activo1"

-...
+#. modules: sale_management
+#: model:ir.model.fields,field_description:sale_management.field_sale_order_template__active
+msgid "Active"
+msgstr "Activo2"
  1. Re-import the file modified and check the changes were applied
  2. Repeat step 1 (re-export in the same way)
  3. Check the msgid was grouped and the second term was deleted

The new PO file looks like the original one

...

#. modules: account, sale_management
#: model:ir.model.fields,field_description:account.field_account_account_tag__active
#: model:ir.model.fields,field_description:sale_management.field_sale_order_template__active
#: model:ir.model.fields.selection,name:account.selection__account_lock_exception__state__active
#: model_terms:ir.ui.view,arch_db:account.view_account_tax_search
msgid "Active"
msgstr "Activo1"

...

See the video:

  • IMAGE ALT TEXT HERE

Notice this is the purpose of the check, so it is a valid case.

Also, notice you are using a po file for 2 modules, so maybe it should be used in MODULE/i18n_extra/fr_be.po instead of MODULE/i18n/fr_be.po where you can maintain manually the po file without exporting and we can disable this check for this extra folder (It needs a change)

@luisg123v
Copy link

@Ahmed-Maghraoui-Eezee-It,

it's not the same term, the first translation is related to a view in the current custom module, and the second is related to a selection field in a standard module.

I think this is the source of the issue. Your file i18n/fr_BE.po is not intended to contain translations from other modules, only for the same module. When you re-export translations, you should only include translations from the module they're contained on. For translating other modules, you should use the i18n_extra folder.

Maybe we can disable the check for i18n_extra translations, as suggested by @moylop260, but I think you wouldn't need that change, unless you need to translate the same term of several other modules different from the custom one.

moylop260 added a commit to vauxoo-dev/odoo-pre-commit-hooks that referenced this issue Jan 30, 2025
Odoo exports translations grouped by "msgid" and delete duplicated

if you will not use odoo exports feature so you will need to manage manually the po file

It could be in i18n_extra in order to ignore the Odoo's normal flow

More info about OCA#122
moylop260 added a commit to vauxoo-dev/odoo-pre-commit-hooks that referenced this issue Jan 30, 2025
Odoo exports translations grouped by "msgid" and delete duplicated

if you will not use odoo exports feature so you will need to manage manually the po file

It could be in i18n_extra in order to ignore the Odoo's normal flow

More info about OCA#122
moylop260 added a commit to vauxoo-dev/odoo-pre-commit-hooks that referenced this issue Jan 30, 2025
Odoo exports translations grouped by "msgid" and delete duplicated

if you will not use odoo exports feature so you will need to manage manually the po file

It could be in i18n_extra in order to ignore the Odoo's normal flow

More info about OCA#122
@moylop260
Copy link
Collaborator

Please, review:
#123

I have added a better message but I think it could be even better

Could you check it, please?

@Ahmed-Maghraoui-Eezee-It
Copy link
Author

Thank you so much @moylop260 @luisg123v

Turns out adding the translations to the i18n_extra was exactly what I needed.
Sorry for the hassle, but I really appreciate your help!

moylop260 added a commit that referenced this issue Jan 31, 2025
Odoo exports translations grouped by "msgid" and deletes duplicated

if you will not use the Odoo export feature so you will need to manage manually the PO file

These kind of files should be in `i18n_extra` folder in order to ignore `po-duplicate-message-definition` check

More info about #122
@moylop260
Copy link
Collaborator

@Ahmed-Maghraoui-Eezee-It

Thank you for reporting the issue

IMHO it is a valid case

I only needed to understand it very well in order to know what was the best fix for that

It will be released in v0.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants