[FIX] mail: fallback on English message

In case of bad translation that doesn't contain the placeholder

Context:
A bad Japanese translation was inserted

  #. module: mail
  #: code:addons/mail/models/mail_thread.py:0
  #, python-format
  msgid "Create new %(document)s"
  msgstr "新しい%(ドキュメント)を作成する"

The translation has been corrected but use the 14.0 syntax of _ method
to include placeholders and fallback on the English source term in
case of bad translation
cf odoo/odoo#52155

closes odoo/odoo#65586

X-original-commit: 48cc6b1f2b3208e8affd5f6a261751fe973c2091
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
Martin Trigaux
2021-02-05 09:25:40 +00:00
parent 8015bdeb4c
commit 6e6f5bd599
5 changed files with 29 additions and 31 deletions
+4 -4
View File
@@ -326,8 +326,8 @@ class MailActivity(models.Model):
model.check_access_rights('read')
except exceptions.AccessError:
raise exceptions.UserError(
_('Assigned user %s has no access to the document and is not able to handle this activity.') %
activity.user_id.display_name)
_('Assigned user %s has no access to the document and is not able to handle this activity.',
activity.user_id.display_name))
else:
try:
target_user = activity.user_id
@@ -339,8 +339,8 @@ class MailActivity(models.Model):
model.browse(activity.res_id).check_access_rule('read')
except exceptions.AccessError:
raise exceptions.UserError(
_('Assigned user %s has no access to the document and is not able to handle this activity.') %
activity.user_id.display_name)
_('Assigned user %s has no access to the document and is not able to handle this activity.',
activity.user_id.display_name))
# ------------------------------------------------------
# ORM overrides
+13 -13
View File
@@ -298,7 +298,7 @@ class Channel(models.Model):
channel_info['is_pinned'] = False
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', partner.id), channel_info)
if not self.email_send:
notification = _('<div class="o_mail_notification">left <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>') % (self.id, self.name,)
notification = _('<div class="o_mail_notification">left <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>', self.id, self.name)
# post 'channel left' message as root since the partner just unsubscribed from the channel
self.sudo().message_post(body=notification, subtype_xmlid="mail.mt_comment", author_id=partner.id)
return result
@@ -339,14 +339,14 @@ class Channel(models.Model):
channel.write({'channel_last_seen_partner_ids': [Command.create({'partner_id': partner_id}) for partner_id in partners_to_add.ids]})
for partner in partners_to_add:
if partner.id != self.env.user.partner_id.id:
notification = _('<div class="o_mail_notification">%(author)s invited %(new_partner)s to <a href="#" class="o_channel_redirect" data-oe-id="%(channel_id)s">#%(channel_name)s</a></div>') % {
'author': self.env.user.display_name,
'new_partner': partner.display_name,
'channel_id': channel.id,
'channel_name': channel.name,
}
notification = _('<div class="o_mail_notification">%(author)s invited %(new_partner)s to <a href="#" class="o_channel_redirect" data-oe-id="%(channel_id)s">#%(channel_name)s</a></div>',
author=self.env.user.display_name,
new_partner=partner.display_name,
channel_id=channel.id,
channel_name=channel.name,
)
else:
notification = _('<div class="o_mail_notification">joined <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>') % (channel.id, channel.name,)
notification = _('<div class="o_mail_notification">joined <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>', channel.id, channel.name)
self.message_post(body=notification, message_type="notification", subtype_xmlid="mail.mt_comment", author_id=partner.id, notify_by_email=False)
# broadcast the channel header to the added partner
@@ -362,8 +362,8 @@ class Channel(models.Model):
if failed:
raise UserError(
_('Following invites are invalid as user groups do not match: %s') %
', '.join('%s (channel %s)' % (partner.name, channel.name) for channel, partner in failed)
_('Following invites are invalid as user groups do not match: %s',
', '.join('%s (channel %s)' % (partner.name, channel.name) for channel, partner in failed))
)
def _can_invite(self, partner_id):
@@ -978,7 +978,7 @@ class Channel(models.Model):
self.ensure_one()
added = self.action_follow()
if added and self.channel_type == 'channel' and not self.email_send:
notification = _('<div class="o_mail_notification">joined <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>') % (self.id, self.name,)
notification = _('<div class="o_mail_notification">joined <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>', self.id, self.name)
self.message_post(body=notification, message_type="notification", subtype_xmlid="mail.mt_comment")
if added and self.moderation_guidelines:
@@ -1002,7 +1002,7 @@ class Channel(models.Model):
'public': privacy,
'email_send': False,
})
notification = _('<div class="o_mail_notification">created <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>') % (new_channel.id, new_channel.name,)
notification = _('<div class="o_mail_notification">created <a href="#" class="o_channel_redirect" data-oe-id="%s">#%s</a></div>', new_channel.id, new_channel.name)
new_channel.message_post(body=notification, message_type="notification", subtype_xmlid="mail.mt_comment")
channel_info = new_channel.channel_info('creation')[0]
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), channel_info)
@@ -1105,7 +1105,7 @@ class Channel(models.Model):
else:
all_channel_partners = self.env['mail.channel.partner'].with_context(active_test=False)
channel_partners = all_channel_partners.search([('partner_id', '!=', partner.id), ('channel_id', '=', self.id)])
msg = _("You are in a private conversation with <b>@%s</b>.") % (channel_partners[0].partner_id.name if channel_partners else _('Anonymous'))
msg = _("You are in a private conversation with <b>@%s</b>.", channel_partners[0].partner_id.name if channel_partners else _('Anonymous'))
msg += self._execute_command_help_message_extra()
self._send_transient_message(partner, msg)
+2 -2
View File
@@ -367,7 +367,7 @@ class Message(models.Model):
message.id = ANY (%%s)''' % (self._table), ('comment', self.ids,))
if self._cr.fetchall():
raise AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation)
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)', self._description, operation)
+ ' - ({} {}, {} {})'.format(_('Records:'), self.ids[:6], _('User:'), self._uid)
)
@@ -580,7 +580,7 @@ class Message(models.Model):
if not self.browse(messages_to_check).exists():
return
raise AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation)
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)', self._description, operation)
+ ' - ({} {}, {} {})'.format(_('Records:'), list(messages_to_check)[:6], _('User:'), self._uid)
)
+1 -1
View File
@@ -268,7 +268,7 @@ class MailRenderMixin(models.AbstractModel):
render_result = view._render(variables, engine='ir.qweb', minimal_qcontext=True)
except Exception as e:
_logger.info("Failed to render template : %s (%d)" % (template_src, view.id), exc_info=True)
raise UserError(_("Failed to render template : %s (%d)") % (template_src, view.id))
raise UserError(_("Failed to render template : %s (%d)", template_src, view.id))
results[record.id] = render_result
return results
+9 -11
View File
@@ -377,26 +377,24 @@ class MailThread(models.AbstractModel):
email_link = "<a href='mailto:%(email)s'>%(email)s</a>" % {'email': alias.display_name}
if nothing_here:
return "<p class='o_view_nocontent_smiling_face'>%(dyn_help)s</p>" % {
'dyn_help': _("Add a new %(document)s or send an email to %(email_link)s") % {
'document': document_name,
'email_link': email_link
}
'dyn_help': _("Add a new %(document)s or send an email to %(email_link)s",
document=document_name,
email_link=email_link,
)
}
# do not add alias two times if it was added previously
if "oe_view_nocontent_alias" not in help:
return "%(static_help)s<p class='oe_view_nocontent_alias'>%(dyn_help)s</p>" % {
'static_help': help,
'dyn_help': _("Create new %(document)s by sending an email to %(email_link)s") % {
'document': document_name,
'email_link': email_link,
}
'dyn_help': _("Create new %(document)s by sending an email to %(email_link)s",
document=document_name,
email_link=email_link,
)
}
if nothing_here:
return "<p class='o_view_nocontent_smiling_face'>%(dyn_help)s</p>" % {
'dyn_help': _("Create new %(document)s") % {
'document': document_name,
}
'dyn_help': _("Create new %(document)s", document=document_name),
}
return help