PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 31, 2022

[FIXED] How to keep translations separated where the same word is used in English but a different one in other languages?

 August 31, 2022     multilingual, odoo, po, poedit, translation     No comments   

Issue

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?


Solution

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.



Answered By - CZoellner
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing