OCA / odoo-pre-commit-hooks

Linters of Odoo addons that complement pylint-odoo
GNU Affero General Public License v3.0
10 stars 12 forks source link

Is it false positive of po-duplicate-message-definition message? #92

Closed voronind closed 11 months ago

voronind commented 11 months ago

Why this example is not false positive? https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.0.29/test_repo/broken_module/i18n/es.po#L65

We translates messages with different xml ids. This messages has different translated msgstr.

How we must translate terms with many values (i.e. key, body)?

pedrobaeza commented 11 months ago

It's totally correct to report that as incorrect. PO files by definition shouldn't have duplicated msgid. For the example you put, the correct way to put it is:

#. module: broken_module
#: model:ir.model.fields,field_description5:broken_module.field_wizard_description5
#: model:ir.model.fields,field_description10:broken_module.field_wizard_description10
#, python-format
msgid "One variable {variable1}"
msgstr "Translated 2 {variable1} {variable2}"

Closing as answered.

voronind commented 11 months ago

@moylop260 We have 2 models. In many languages translations for this two terms will be different. How do right po files for that?

class KeyboardKey(models.Model):
    _name = 'keyboard.key'

    key = fields.Char(string='Key')

class LockKey(models.Model):
    _name = 'lock.key'

    key = fields.Char(string='Key')
voronind commented 11 months ago

@pedrobaeza You didn't answer how to translate ambiguous terms

luisg123v commented 11 months ago

Hi @voronind,

We have 2 models. In many languages translations for this two terms will be different. How do right po files for that?,

I understand the use case, I've faced the same situation myself. Unfortunately, the PO format doesn't support translating the same term on different ways, at least not without an additional identifier.

This is not even supported by Odoo. You could for example test translating different terms on different ways and then re-exporting module translations, and you will notice all of them are combined on to a single term.

You could also try tools like msgfmt over PO files that containg original term (msgid) several times and you will notice it complains. For instance, given a file like the following:

...
#. module: somemodule
#: model:ir.model.fields,field_description:somemodule.field_account_move__partner_id
msgid "Partner"
msgstr "Cliente"

#. module: somemodule
#: model:ir.model.fields,field_description:somemodule.field_account_journal__partner_id
msgid "Partner"
msgstr "Proveedor"

If I run msgfmt over the above file, I get an error:

$ msgfmt  es.po
es.po:25: duplicate message definition...
es.po:21: ...this is the location of the first definition
msgfmt: found 1 fatal error

To summarize, it's actually expected the lint complaining and Odoo doesn't provide a mechanism to translate the same term on different ways on a persistent manner.

Regards,

CC @antonag32

voronind commented 11 months ago

PO format supports ambiguous terms with context specifier (msgctxt) that's why msgfmt report error. Odoo uses PO entitie's reference value to translate same terms.

I created test_trans module with model.

class TestTranslate(models.Model):
    _name = 'test.translate'

    field_1 = fields.Char('Field')
    field_2 = fields.Char('Field')

Added to i18n file

#. module: test_trans
#: model:ir.model.fields,field_description:test_trans.field_test_translate_field_1
msgid "Field"
msgstr "Trans 1"

#. module: test_trans
#: model:ir.model.fields,field_description:test_trans.field_test_translate_field_2
msgid "Field"
msgstr "Trans 2"

Added form view with fields field_1 and field_2. Odoo shows form with "Trans 1" and "Trans 2" labels.
Odoo 11