[IMP] *: translations improvements

Avoid concatenation of translated strings & raw values and/or other 
translated values, and use the new _ API (by providing the formatting 
values to ensure the fallback on the english terms in case of wrong 
translation).

By including the expected values inside the string to translate, we 
ensure that the formatted values are included at the right place in the 
resulting translated text.

This also provides more information on the string to translate to 
the translators, s.t. the chosen terms for the translations can be more 
adapted to the translation context.

closes odoo/odoo#54635

Related: odoo/enterprise#11925
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2020-07-23 12:13:19 +00:00
parent b932ea75fe
commit e8893f84ab
15 changed files with 62 additions and 46 deletions
@@ -85,9 +85,9 @@ class AccountAnalyticLine(models.Model):
@api.model
def view_header_get(self, view_id, view_type):
context = (self._context or {})
header = False
if context.get('account_id', False):
analytic_account = self.env['account.analytic.account'].search([('id', '=', context['account_id'])], limit=1)
header = _('Entries: ') + (analytic_account.name or '')
return header
if self.env.context.get('account_id'):
return _(
"Entries: %(account)s",
account=self.env['account.analytic.account'].browse(self.env.context['account_id']).name
)
return super().view_header_get(view_id, view_type)
@@ -524,7 +524,11 @@ class account_journal(models.Model):
action['context'] = ctx
if ctx.get('use_domain', False):
action['domain'] = isinstance(ctx['use_domain'], list) and ctx['use_domain'] or ['|', ('journal_id', '=', self.id), ('journal_id', '=', False)]
action['name'] += ' for journal ' + self.name
action['name'] = _(
"%(action)s for journal %(journal)s",
action=action["name"],
journal=self.name,
)
return action
def create_bank_statement(self):
+2 -2
View File
@@ -1295,9 +1295,9 @@ class AccountMove(models.Model):
vendor_display_name = move.partner_id.display_name
if not vendor_display_name:
if move.invoice_source_email:
vendor_display_name = _('@From: ') + move.invoice_source_email
vendor_display_name = _('@From: %(email)s', email=move.invoice_source_email)
else:
vendor_display_name = _('#Created by: %s') % (move.sudo().create_uid.name or self.env.user.name)
vendor_display_name = _('#Created by: %s', move.sudo().create_uid.name or self.env.user.name)
move.invoice_partner_display_name = vendor_display_name
def _compute_payments_widget_to_reconcile_info(self):
+1 -1
View File
@@ -265,7 +265,7 @@ class EventRegistration(models.Model):
elif event_date.month == (today + relativedelta(months=+1)).month:
return _('next month')
else:
return _('on ') + format_datetime(self.env, self.event_begin_date, tz=self.event_id.date_tz, dt_format='medium')
return _('on %(date)s', date=format_datetime(self.env, self.event_begin_date, tz=self.event_id.date_tz, dt_format='medium'))
def _get_registration_summary(self):
self.ensure_one()
@@ -375,9 +375,9 @@ class AccountEdiFormat(models.Model):
discount["seq"] = invoice_line_form.sequence + 1
if total_discount_amount < 0:
discount["name"] = _('DISCOUNT: ') + invoice_line_form.name
discount["name"] = _('DISCOUNT: %s', invoice_line_form.name)
else:
discount["name"] = _('EXTRA CHARGE: ') + invoice_line_form.name
discount["name"] = _('EXTRA CHARGE: %s', invoice_line_form.name)
discount["amount"] = total_discount_amount
discount["tax"] = []
for tax in invoice_line_form.tax_ids:
+1 -1
View File
@@ -501,7 +501,7 @@ class MrpWorkorder(models.Model):
timeline.create({
'workorder_id': self.id,
'workcenter_id': self.workcenter_id.id,
'description': _('Time Tracking: ') + self.env.user.name,
'description': _('Time Tracking: %(user)s', user=self.env.user.name),
'loss_id': loss_id[0].id,
'date_start': datetime.now(),
'user_id': self.env.user.id, # FIXME sle: can be inconsistent with company_id
+3 -3
View File
@@ -461,9 +461,9 @@ class PosConfig(models.Model):
for config in self:
last_session = self.env['pos.session'].search([('config_id', '=', config.id)], limit=1)
if (not last_session) or (last_session.state == 'closed'):
result.append((config.id, config.name + ' (' + _('not used') + ')'))
continue
result.append((config.id, config.name + ' (' + last_session.user_id.name + ')'))
result.append((config.id, _("%(pos_name)s (not used)", pos_name=config.name)))
else:
result.append((config.id, "%s (%s)" % (config.name, last_session.user_id.name)))
return result
@api.model
+8 -3
View File
@@ -1025,9 +1025,14 @@ class PosSession(models.Model):
sessions = self.search([('start_at', '<=', (fields.datetime.now() - timedelta(days=7))), ('state', '!=', 'closed')])
for session in sessions:
if self.env['mail.activity'].search_count([('res_id', '=', session.id), ('res_model', '=', 'pos.session')]) == 0:
session.activity_schedule('point_of_sale.mail_activity_old_session',
user_id=session.user_id.id, note=_("Your PoS Session is open since ") + fields.Date.to_string(session.start_at)
+ _(", we advise you to close it and to create a new one."))
session.activity_schedule(
'point_of_sale.mail_activity_old_session',
user_id=session.user_id.id,
note=_(
"Your PoS Session is open since %(date)s, we advise you to close it and to create a new one.",
date=session.start_at,
)
)
def _warning_balance_closing(self):
self.ensure_one()
+5 -3
View File
@@ -548,10 +548,12 @@ class ProductProduct(models.Model):
@api.model
def view_header_get(self, view_id, view_type):
res = super(ProductProduct, self).view_header_get(view_id, view_type)
if self._context.get('categ_id'):
return _('Products: ') + self.env['product.category'].browse(self._context['categ_id']).name
return res
return _(
'Products: %(category)s',
category=self.env['product.category'].browse(self.env.context['categ_id']).name,
)
return super().view_header_get(view_id, view_type)
def open_pricelist_rules(self):
self.ensure_one()
+8 -5
View File
@@ -1229,12 +1229,15 @@ class SaleOrderLine(models.Model):
order_lines = self.filtered(lambda x: x.order_id == order)
msg = "<b>" + _("The ordered quantity has been updated.") + "</b><ul>"
for line in order_lines:
msg += "<li> %s:" % (line.product_id.display_name,)
msg += "<br/>" + _("Ordered Quantity") + ": %s -> %s <br/>" % (
line.product_uom_qty, float(values['product_uom_qty']),)
msg += "<li> %s: <br/>" % line.product_id.display_name
msg += _(
"Ordered Quantity: %(old_qty)s -> %(new_qty)s",
old_qty=line.product_uom_qty,
new_qty=values["product_uom_qty"]
) + "<br/>"
if line.product_id.type in ('consu', 'product'):
msg += _("Delivered Quantity") + ": %s <br/>" % (line.qty_delivered,)
msg += _("Invoiced Quantity") + ": %s <br/>" % (line.qty_invoiced,)
msg += _("Delivered Quantity: %s", line.qty_delivered) + "<br/>"
msg += _("Invoiced Quantity: %s", line.qty_invoiced) + "<br/>"
msg += "</ul>"
order.message_post(body=msg)
+7 -9
View File
@@ -132,7 +132,7 @@ class SaleOrder(models.Model):
def _get_reward_values_discount(self, program):
if program.discount_type == 'fixed_amount':
return [{
'name': _("Discount: ") + program.name,
'name': _("Discount: %s", program.name),
'product_id': program.discount_line_product_id.id,
'price_unit': - self._get_reward_values_discount_fixed_amount(program),
'product_uom_qty': 1.0,
@@ -150,7 +150,7 @@ class SaleOrder(models.Model):
taxes = self.fiscal_position_id.map_tax(line.tax_id)
reward_dict[line.tax_id] = {
'name': _("Discount: ") + program.name,
'name': _("Discount: %s", program.name),
'product_id': program.discount_line_product_id.id,
'price_unit': - discount_line_amount,
'product_uom_qty': 1.0,
@@ -174,14 +174,12 @@ class SaleOrder(models.Model):
else:
taxes = self.fiscal_position_id.map_tax(line.tax_id)
tax_name = ""
if len(taxes) == 1:
tax_name = " - " + _("On product with following tax: ") + ', '.join(taxes.mapped('name'))
elif len(taxes) > 1:
tax_name = " - " + _("On product with following taxes: ") + ', '.join(taxes.mapped('name'))
reward_dict[line.tax_id] = {
'name': _("Discount: ") + program.name + tax_name,
'name': _(
"Discount: %(program)s - On product with following taxes: %(taxes)s",
program=program.name,
taxes=", ".join(taxes.mapped('name')),
),
'product_id': program.discount_line_product_id.id,
'price_unit': - discount_line_amount,
'product_uom_qty': 1.0,
@@ -28,7 +28,7 @@ class SaleOrder(models.Model):
delivery_line = self.order_line.filtered(lambda x: x.is_delivery)
taxes = self.fiscal_position_id.map_tax(delivery_line.product_id.taxes_id)
return {
'name': _("Discount: ") + program.name,
'name': _("Discount: %s", program.name),
'product_id': program.discount_line_product_id.id,
'price_unit': delivery_line and - delivery_line.price_unit or 0.0,
'product_uom_qty': 1.0,
+4 -1
View File
@@ -391,7 +391,10 @@ class Product(models.Model):
def view_header_get(self, view_id, view_type):
res = super(Product, self).view_header_get(view_id, view_type)
if not res and self._context.get('active_id') and self._context.get('active_model') == 'stock.location':
res = '%s%s' % (_('Products: '), self.env['stock.location'].browse(self._context['active_id']).name)
return _(
'Products: %(location)s',
location=self.env['stock.location'].browse(self._context['active_id']).name,
)
return res
@api.model
+3 -3
View File
@@ -138,12 +138,12 @@ class StockRule(models.Model):
if self.action in ('push', 'pull', 'pull_push'):
suffix = ""
if self.procure_method == 'make_to_order' and self.location_src_id:
suffix = _("<br>A need is created in <b>%s</b> and a rule will be triggered to fulfill it.") % (source)
suffix = _("<br>A need is created in <b>%s</b> and a rule will be triggered to fulfill it.", source)
if self.procure_method == 'mts_else_mto' and self.location_src_id:
suffix = _("<br>If the products are not available in <b>%s</b>, a rule will be triggered to bring products in this location.", source)
message_dict = {
'pull': _('When products are needed in <b>%s</b>, <br/> <b>%s</b> are created from <b>%s</b> to fulfill the need.') % (destination, operation, source) + suffix,
'push': _('When products arrive in <b>%s</b>, <br/> <b>%s</b> are created to send them in <b>%s</b>.') % (source, operation, destination)
'pull': _('When products are needed in <b>%s</b>, <br/> <b>%s</b> are created from <b>%s</b> to fulfill the need.', destination, operation, source) + suffix,
'push': _('When products arrive in <b>%s</b>, <br/> <b>%s</b> are created to send them in <b>%s</b>.', source, operation, destination)
}
return message_dict
+6 -5
View File
@@ -890,11 +890,12 @@ class Partner(models.Model):
@api.model
def view_header_get(self, view_id, view_type):
res = super(Partner, self).view_header_get(view_id, view_type)
if res: return res
if not self._context.get('category_id'):
return False
return _('Partners: ') + self.env['res.partner.category'].browse(self._context['category_id']).name
if self.env.context.get('category_id'):
return _(
'Partners: %(category)s',
category=self.env['res.partner.category'].browse(self.env.context['category_id']).name,
)
return super().view_header_get(view_id, view_type)
@api.model
@api.returns('self')