summaryrefslogtreecommitdiff
path: root/addons/gamification
diff options
context:
space:
mode:
authorOdoo's Mergebot <xmo+roboto@odoo.com>2020-06-18 13:51:48 +0200
committerGitHub <noreply@github.com>2020-06-18 13:51:48 +0200
commite617aa91c536093f481da28b0cf061a6abe55b2a (patch)
tree74fbff684e24f5389db77e63ee74f236039a3afb /addons/gamification
parentcb7a7deec5c1eda8c156e1b1f9e1f1e38d0abda2 (diff)
parent80e97e98ce76067db1079af8feeef667cfadf837 (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')
-rw-r--r--addons/gamification/models/challenge.py12
-rw-r--r--addons/gamification/models/goal.py16
2 files changed, 19 insertions, 9 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.")
diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py
index 9a14a1438c3..e26ac0b37ff 100644
--- a/addons/gamification/models/goal.py
+++ b/addons/gamification/models/goal.py
@@ -111,11 +111,17 @@ class GoalDefinition(models.Model):
Model = self.env[definition.model_id.model]
field = Model._fields.get(definition.field_id.name)
if not (field and field.store):
- raise exceptions.UserError(
- _("The model configuration for the definition %s seems incorrect, please check it.\n\n%s not stored") % (definition.name, definition.field_id.name))
+ raise exceptions.UserError(_(
+ "The model configuration for the definition %(name)s seems incorrect, please check it.\n\n%(field_name)s not stored",
+ name=definition.name,
+ field_name=definition.field_id.name
+ ))
except KeyError as e:
- raise exceptions.UserError(
- _("The model configuration for the definition %s seems incorrect, please check it.\n\n%s not found") % (definition.name, e))
+ raise exceptions.UserError(_(
+ "The model configuration for the definition %(name)s seems incorrect, please check it.\n\n%(error)s not found",
+ name=definition.name,
+ error=e
+ ))
@api.model
def create(self, vals):
@@ -430,7 +436,7 @@ class Goal(models.Model):
if self.computation_mode == 'manually':
# open a wizard window to update the value manually
action = {
- 'name': _("Update %s") % self.definition_id.name,
+ 'name': _("Update %s", self.definition_id.name),
'id': self.id,
'type': 'ir.actions.act_window',
'views': [[False, 'form']],