diff options
| author | Odoo's Mergebot <xmo+roboto@odoo.com> | 2020-06-18 13:51:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-18 13:51:48 +0200 |
| commit | e617aa91c536093f481da28b0cf061a6abe55b2a (patch) | |
| tree | 74fbff684e24f5389db77e63ee74f236039a3afb /addons/gamification/models/challenge.py | |
| parent | cb7a7deec5c1eda8c156e1b1f9e1f1e38d0abda2 (diff) | |
| parent | 80e97e98ce76067db1079af8feeef667cfadf837 (diff) | |
[MERGE] tools: better placeholder support for _
Support two new syntaxes with `_()` method:
_("This is so %s") % 2019
_("Text with %s placeholders", 42)
_("Text with %(num)s placeholders %(symbol)s", num=42, symbol="🧀")
The main benefit is to have a fallback on the source string if formating the
translated string fails (e.g. "Foo %s" translated "Foo s%").
This PR converted most (but not all) calls to _ using placeholders to use the
new syntax. Hopefully, the remaining ones will be converted in the future and
avoid technical debt.
Use named placeholders when needed. If more than one placeholder is present in a
string, using named placeholder can be beneficial to reorder the placehodler
position (for languages like Japanese that do not use the same phrase
construction). On some sentences, it also brings clarity on the meaning of the
placeholders.
closes odoo/odoo#52155
Task-id: 1853119
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Diffstat (limited to 'addons/gamification/models/challenge.py')
| -rw-r--r-- | addons/gamification/models/challenge.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index c424a8c4b28..93efdef0d9b 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -596,7 +596,7 @@ class Challenge(models.Model): def accept_challenge(self): user = self.env.user sudoed = self.sudo() - sudoed.message_post(body=_("%s has joined the challenge") % user.name) + sudoed.message_post(body=_("%s has joined the challenge", user.name)) sudoed.write({'invited_user_ids': [(3, user.id)], 'user_ids': [(4, user.id)]}) return sudoed._generate_goals_from_challenge() @@ -604,7 +604,7 @@ class Challenge(models.Model): """The user discard the suggested challenge""" user = self.env.user sudoed = self.sudo() - sudoed.message_post(body=_("%s has refused the challenge") % user.name) + sudoed.message_post(body=_("%s has refused the challenge", user.name)) return sudoed.write({'invited_user_ids': (3, user.id)}) def _check_challenge_reward(self, force=False): @@ -652,11 +652,15 @@ class Challenge(models.Model): if challenge_ended: # open chatter message - message_body = _("The challenge %s is finished.") % challenge.name + message_body = _("The challenge %s is finished.", challenge.name) if rewarded_users: user_names = rewarded_users.name_get() - message_body += _("<br/>Reward (badge %s) for every succeeding user was sent to %s.") % (challenge.reward_id.name, ", ".join(name for (user_id, name) in user_names)) + message_body += _( + "<br/>Reward (badge %(badge_name)s) for every succeeding user was sent to %(users)s.", + badge_name=challenge.reward_id.name, + users=", ".join(name for (user_id, name) in user_names) + ) else: message_body += _("<br/>Nobody has succeeded to reach every goal, no badge is rewarded for this challenge.") |
