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/mail | |
| 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/mail')
| -rw-r--r-- | addons/mail/controllers/main.py | 2 | ||||
| -rw-r--r-- | addons/mail/models/mail_activity.py | 4 | ||||
| -rw-r--r-- | addons/mail/models/mail_blacklist.py | 2 | ||||
| -rw-r--r-- | addons/mail/models/mail_channel.py | 6 | ||||
| -rw-r--r-- | addons/mail/models/mail_render_mixin.py | 2 | ||||
| -rw-r--r-- | addons/mail/models/mail_template.py | 6 | ||||
| -rw-r--r-- | addons/mail/models/mail_thread.py | 28 | ||||
| -rw-r--r-- | addons/mail/models/mail_thread_blacklist.py | 4 | ||||
| -rw-r--r-- | addons/mail/wizard/invite.py | 2 |
9 files changed, 34 insertions, 22 deletions
diff --git a/addons/mail/controllers/main.py b/addons/mail/controllers/main.py index 8f3b1694098..46d14831dd5 100644 --- a/addons/mail/controllers/main.py +++ b/addons/mail/controllers/main.py @@ -37,7 +37,7 @@ class MailController(http.Controller): def _check_token_and_record_or_redirect(cls, model, res_id, token): comparison = cls._check_token(token) if not comparison: - _logger.warning(_('Invalid token in route %s') % request.httprequest.url) + _logger.warning(_('Invalid token in route %s', request.httprequest.url)) return comparison, None, cls._redirect_to_messaging() try: record = request.env[model].browse(res_id).exists() diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index dd92b4a17b3..81e04898477 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -433,7 +433,9 @@ class MailActivity(models.Model): record.message_notify( partner_ids=activity.user_id.partner_id.ids, body=body, - subject=_('%s: %s assigned to you') % (activity.res_name, activity.summary or activity.activity_type_id.name), + subject=_('%(activity_name)s: %(summary)s assigned to you', + activity_name=activity.res_name, + summary=activity.summary or activity.activity_type_id.name), record_name=activity.res_name, model_description=model_description, email_layout_xmlid='mail.mail_notification_light', diff --git a/addons/mail/models/mail_blacklist.py b/addons/mail/models/mail_blacklist.py index cbe5cc6693b..059c6e9e629 100644 --- a/addons/mail/models/mail_blacklist.py +++ b/addons/mail/models/mail_blacklist.py @@ -28,7 +28,7 @@ class MailBlackList(models.Model): for value in values: email = tools.email_normalize(value.get('email')) if not email: - raise UserError(_('Invalid email address %r') % value['email']) + raise UserError(_('Invalid email address %r', value['email'])) if email in all_emails: continue all_emails.append(email) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 1d7c35fabc9..23f63f4dad3 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -427,7 +427,7 @@ class Channel(models.Model): 'email_from': company.catchall_formatted or company.email_formatted, 'author_id': self.env.user.partner_id.id, 'body_html': view._render({'channel': self, 'partner': partner}, engine='ir.qweb', minimal_qcontext=True), - 'subject': _("Guidelines of channel %s") % self.name, + 'subject': _("Guidelines of channel %s", self.name), 'recipient_ids': [(4, partner.id)] } mail = self.env['mail.mail'].sudo().create(create_values) @@ -976,7 +976,7 @@ class Channel(models.Model): def _execute_command_help(self, **kwargs): partner = self.env.user.partner_id if self.channel_type == 'channel': - msg = _("You are in channel <b>#%s</b>.") % self.name + msg = _("You are in channel <b>#%s</b>.", self.name) if self.public == 'private': msg += _(" This channel is private. People must be invited to join it.") else: @@ -1016,6 +1016,6 @@ class Channel(models.Model): msg = _("You are alone in this channel.") else: dots = "..." if len(members) != len(self.channel_partner_ids) - 1 else "" - msg = _("Users in this channel: %s %s and you.") % (", ".join(members), dots) + msg = _("Users in this channel: %(members)s %(dots)s and you.", members=", ".join(members), dots=dots) self._send_transient_message(partner, msg) diff --git a/addons/mail/models/mail_render_mixin.py b/addons/mail/models/mail_render_mixin.py index ddd32659a03..79b66e55f8b 100644 --- a/addons/mail/models/mail_render_mixin.py +++ b/addons/mail/models/mail_render_mixin.py @@ -316,7 +316,7 @@ class MailRenderMixin(models.AbstractModel): render_result = template.render(variables) except Exception as e: _logger.info("Failed to render template : %s" % e, exc_info=True) - raise UserError(_("Failed to render template : %s") % e) + raise UserError(_("Failed to render template : %s", e)) if render_result == u"False": render_result = u"" results[record.id] = render_result diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index f8f90aea5fd..92783104b65 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -74,7 +74,7 @@ class MailTemplate(models.Model): @api.returns('self', lambda value: value.id) def copy(self, default=None): default = dict(default or {}, - name=_("%s (copy)") % self.name) + name=_("%s (copy)", self.name)) return super(MailTemplate, self).copy(default=default) def unlink_action(self): @@ -88,7 +88,7 @@ class MailTemplate(models.Model): view = self.env.ref('mail.email_compose_message_wizard_form') for template in self: - button_name = _('Send Mail (%s)') % template.name + button_name = _('Send Mail (%s)', template.name) action = ActWindow.create({ 'name': button_name, 'type': 'ir.actions.act_window', @@ -200,7 +200,7 @@ class MailTemplate(models.Model): else: res = report._render([res_id]) if not res: - raise UserError(_('Unsupported report type %s found.') % report.report_type) + raise UserError(_('Unsupported report type %s found.', report.report_type)) result, format = res # TODO in trunk, change return format to binary to match message_post expected format diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index ee16931f25e..dcadca5b281 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -544,7 +544,7 @@ class MailThread(models.AbstractModel): """ self.ensure_one() doc_name = self.env['ir.model']._get(self._name).name - return _('%s created') % doc_name + return _('%s created', doc_name) def _track_subtype(self, init_values): """ Give the subtypes triggered by the changes on the record according @@ -671,7 +671,7 @@ class MailThread(models.AbstractModel): def _routing_warn(self, error_message, message_id, route, raise_exception=True): """ Tools method used in _routing_check_route: whether to log a warning or raise an error """ - short_message = _("Mailbox unavailable - %s") % error_message + short_message = _("Mailbox unavailable - %s", error_message) full_message = ('Routing mail with Message-Id %s: route %s: %s' % (message_id, route, error_message)) _logger.info(full_message) @@ -791,22 +791,27 @@ class MailThread(models.AbstractModel): self._routing_warn(_('target model unspecified'), message_id, route, raise_exception) return () elif model not in self.env: - self._routing_warn(_('unknown target model %s') % model, message_id, route, raise_exception) + self._routing_warn(_('unknown target model %s', model), message_id, route, raise_exception) return () record_set = self.env[model].browse(thread_id) if thread_id else self.env[model] # Existing Document: check if exists and model accepts the mailgateway; if not, fallback on create if allowed if thread_id: if not record_set.exists(): - self._routing_warn(_('reply to missing document (%s,%s), fall back on document creation') % (model, thread_id), message_id, route, False) + self._routing_warn( + _('reply to missing document (%(model)s,%(thread)s), fall back on document creation', model=model, thread=thread_id), + message_id, + route, + False + ) thread_id = None elif not hasattr(record_set, 'message_update'): - self._routing_warn(_('reply to model %s that does not accept document update, fall back on document creation') % model, message_id, route, False) + self._routing_warn(_('reply to model %s that does not accept document update, fall back on document creation', model), message_id, route, False) thread_id = None # New Document: check model accepts the mailgateway if not thread_id and model and not hasattr(record_set, 'message_new'): - self._routing_warn(_('model %s does not accept document creation') % model, message_id, route, raise_exception) + self._routing_warn(_('model %s does not accept document creation', model), message_id, route, raise_exception) return () # Update message author. We do it now because we need it for aliases (contact settings) @@ -834,7 +839,12 @@ class MailThread(models.AbstractModel): else: error_code = self.env['mail.alias.mixin']._alias_check_contact_on_record(obj, message, message_dict, alias) if error_code is not True: - self._routing_warn(_('alias %s: %s') % (alias.alias_name, error_code or _('unknown error')), message_id, route, False) + self._routing_warn( + _('alias %(name)s: %(error)s', name=alias.alias_name, error=error_code or _('unknown error')), + message_id, + route, + False + ) body = alias._get_alias_bounced_body(message_dict) self._routing_create_bounce_email(email_from, body, message, references=message_id) return False @@ -2595,7 +2605,7 @@ class MailThread(models.AbstractModel): access_link = self._notify_get_action_link('view') if model_name: - view_title = _('View %s') % model_name + view_title = _('View %s', model_name) else: view_title = _('View') @@ -2859,7 +2869,7 @@ class MailThread(models.AbstractModel): assignation_msg = view._render(values, engine='ir.qweb', minimal_qcontext=True) assignation_msg = self.env['mail.render.mixin']._replace_local_links(assignation_msg) record.message_notify( - subject=_('You have been assigned to %s') % record.display_name, + subject=_('You have been assigned to %s', record.display_name), body=assignation_msg, partner_ids=partner_ids, record_name=record.display_name, diff --git a/addons/mail/models/mail_thread_blacklist.py b/addons/mail/models/mail_thread_blacklist.py index 00f6bb95518..f17302f360e 100644 --- a/addons/mail/models/mail_thread_blacklist.py +++ b/addons/mail/models/mail_thread_blacklist.py @@ -93,9 +93,9 @@ class MailBlackListMixin(models.AbstractModel): def _assert_primary_email(self): if not hasattr(self, "_primary_email") or not isinstance(self._primary_email, str): - raise UserError(_('Invalid primary email field on model %s') % self._name) + raise UserError(_('Invalid primary email field on model %s', self._name)) if self._primary_email not in self._fields or self._fields[self._primary_email].type != 'char': - raise UserError(_('Invalid primary email field on model %s') % self._name) + raise UserError(_('Invalid primary email field on model %s', self._name)) def _message_receive_bounce(self, email, partner): """ Override of mail.thread generic method. Purpose is to increment the diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py index bbe67a37cdc..3d96ebe25b6 100644 --- a/addons/mail/wizard/invite.py +++ b/addons/mail/wizard/invite.py @@ -64,7 +64,7 @@ class Invite(models.TransientModel): # send an email if option checked and if a message exists (do not send void emails) if wizard.send_mail and wizard.message and not wizard.message == '<br>': # when deleting the message, cleditor keeps a <br> message = self.env['mail.message'].create({ - 'subject': _('Invitation to follow %s: %s') % (model_name, document.display_name), + 'subject': _('Invitation to follow %(document_model)s: %(document_name)s', document_model=model_name, document_name=document.display_name), 'body': wizard.message, 'record_name': document.display_name, 'email_from': email_from, |
