2

Imagine I have a report, a letter actually, which I need to translate to several languages. I have created a greeting field in the form which is filled programatically by an onchange event method.

if self.partner_id.gender == 'female':
    self.letter_greeting = _('Dear %s %s,') % (         # the translation should be "Estimada"
        self.repr_recipient_id.title.shorcut, surname
    )
elif self.partner_id.gender == 'male':
    self.letter_greeting = _('Dear %s %s,') % (         # translation "Estimado"
        self.repr_recipient_id.title.shorcut, surname
    )
else:
    self.letter_greeting = _('Dear %s %s,') % (         # translation: "Estimado/a"
        self.partner_id.title.shorcut, surname
    )

In that case the word Dear should be translated to different Spanish translations depending on which option is used, this is because we use different termination depending on the gender. Exporting the po file I found that all the options are altogether, that make sense because almost all the cases the translations will be the same, but not in this case:

#. module: custom_module
#: code:addons/custom_module/models/sale_order.py:334
#: code:addons/custom_module/models/sale_order.py:338
#: code:addons/custom_module/models/sale_order.py:342
#, python-format
msgid "Dear %s %s,"
msgstr "Dear %s %s,"

Solutions I can apply directly

  • Put all the terms in different entries to avoid the same translation manually every time I need to update the po file. This can be cumbersome if you have many different words with that problem. If I do it and I open the file with poedit, this error appears: duplicate message definition

    enter image description here

  • Put all the possible combinations with slashes, this is done y some other parts of Odoo. For both gender would be:

#. module: stock
#: model:res.company,msg:stock.res_company
msgid "Dear"
msgstr "Estimado/a"

This is just an example. I can think of many words that look the same in English, but they use different spelling or meanings in other languages depending on the context.

Possible best solutions

  • I don't know if Odoo know anything aboutu the context of a word to know if it was already translated or not. Adding a context manually could solve the problem, at least for words with different meanings.

  • The nicest solution would be to have a parameter to the translation module to make sure that the word is exported as an isolated entry for that especific translation.

Do you think that I am giving to it too much importance haha? Do you know if there is any better solution? Why is poedit not taking into account that problem at all?

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
  • 1
    We have outsourced those semi-static report parts to a odoo model, where the char fields are translateable. With this approach you are a bit more flexible in context of report contents. For salutations we also have build something special. We just extended res.partner.title and implemented functionality to get a full salutation for a partner. It's the same approach (translateable char fields) in the end, but salutations are binded to partners, so we made that one directly on res.partner.title. We even added some gender things on res.partner.title. – CZoellner Dec 08 '20 at 11:07
  • Very good ideas @CZoellner, thanks. If you write that in an answer I will accept it. I was hoping there was something more sofisticated to make difference between those terms, but I am afraid not, or at least within Odoo when exporting the po file. Some [other tranlation tools](https://poeditor.com/kb/duplicate-terms) can take contexts into consideration – ChesuCR Dec 10 '20 at 12:00
  • That would be too much code and i'm probably not allowed to publish the code here ;-) – CZoellner Dec 10 '20 at 13:07
  • @CZoellner No, I don't mean to publish the full code haha, the explanation you have written in the comment is enough for me :) you can post it as an answer – ChesuCR Dec 10 '20 at 13:38

2 Answers2

1

I propose an extension of models res.partner.title and res.partner.

res.partner.title should get a translateable field for saving salutation prefixes like 'Dear' or 'Sehr geehrter' (German). Maybe it's worth to get something about genders, too, but i won't get into detail here about that. You probably want to show the configuring user an example like "Dear Mr. Name" or something like that. A computed field should work.

On res.partner you should just implement either a computed field or just a method to get a full salutation for a partner record.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • I even like more the solution of Andrew for a more general approach. Take a look at it, what do you think? I think for static content is the best one, and yours is good because the user can update tranlations and add more records – ChesuCR Dec 10 '20 at 17:25
  • That can be done with my solution, too. And in his solution there is no hint how to do that in Odoo. For the gender part my solution has everything even Odoo doesn't know anything about genders at all: just create more than one "Dear" or do that like in Andrew's answer. The salutation prefix i've mentioned will then be the real text which will be translated. – CZoellner Dec 11 '20 at 08:22
  • Yes, your solution is great for my example. The Andrew solution can be done directly how he says in Odoo for static content. Just using a different key for each word you want to make a different translation and exporting the English language to translate the words correctly. Even though it'll be redundancy in that document. – ChesuCR Dec 11 '20 at 16:10
1

To some degree this is a linguistics problem. I believe the best solution would be to use a different "Source Language", one made up of keys, and then have English as another Translation. The word "Dear" in English does not have a gender context (and typically, much of English doesn't), while the word "Estimado" in Spanish does. The translation from that Spanish word to English is more appropriately "Masculine Dear." Therefore, using keys as your source language, you would have this:

SourceText (EnglishDescription) -> Translation (English) -> Translation (Spanish)
DearMasculine -> Dear -> Estimado
DearFeminine -> Dear -> Estimada
DearNuetral -> Dear -> Estimado/a
Andrew Jackman
  • 13,781
  • 7
  • 35
  • 44