From e8893f84abcc50dfdfd3173497f388e94310f090 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Wed, 22 Jul 2020 16:52:13 +0000 Subject: [PATCH] [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) --- addons/account/models/account_analytic_line.py | 12 ++++++------ .../account/models/account_journal_dashboard.py | 6 +++++- addons/account/models/account_move.py | 4 ++-- addons/event/models/event_registration.py | 2 +- addons/l10n_it_edi/models/account_edi_format.py | 4 ++-- addons/mrp/models/mrp_workorder.py | 2 +- addons/point_of_sale/models/pos_config.py | 6 +++--- addons/point_of_sale/models/pos_session.py | 11 ++++++++--- addons/product/models/product.py | 8 +++++--- addons/sale/models/sale.py | 13 ++++++++----- addons/sale_coupon/models/sale_order.py | 16 +++++++--------- addons/sale_coupon_delivery/models/sale_order.py | 2 +- addons/stock/models/product.py | 5 ++++- addons/stock/models/stock_rule.py | 6 +++--- odoo/addons/base/models/res_partner.py | 11 ++++++----- 15 files changed, 62 insertions(+), 46 deletions(-) diff --git a/addons/account/models/account_analytic_line.py b/addons/account/models/account_analytic_line.py index 35737d8ab75..80e35b8080b 100644 --- a/addons/account/models/account_analytic_line.py +++ b/addons/account/models/account_analytic_line.py @@ -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) diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index 8be1af1dcd6..55070e0a257 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -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): diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 945608d9c1c..630e29e4427 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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): diff --git a/addons/event/models/event_registration.py b/addons/event/models/event_registration.py index d8dc794b6e4..3f977b3df5d 100644 --- a/addons/event/models/event_registration.py +++ b/addons/event/models/event_registration.py @@ -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() diff --git a/addons/l10n_it_edi/models/account_edi_format.py b/addons/l10n_it_edi/models/account_edi_format.py index c64fcd8f234..e24f3efa2b6 100644 --- a/addons/l10n_it_edi/models/account_edi_format.py +++ b/addons/l10n_it_edi/models/account_edi_format.py @@ -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: diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index ca809e3a1e9..cd7caba0420 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -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 diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 28e10b047fc..f7f1a593826 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -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 diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index f1fb4d0bdc7..3c250bed51f 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -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() diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 3661ee7fe97..c11fa3aac44 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -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() diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 3c9dfc41017..2815aa92761 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1229,12 +1229,15 @@ class SaleOrderLine(models.Model): order_lines = self.filtered(lambda x: x.order_id == order) msg = "" + _("The ordered quantity has been updated.") + "" order.message_post(body=msg) diff --git a/addons/sale_coupon/models/sale_order.py b/addons/sale_coupon/models/sale_order.py index fd979d0524b..73e08c87d55 100644 --- a/addons/sale_coupon/models/sale_order.py +++ b/addons/sale_coupon/models/sale_order.py @@ -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, diff --git a/addons/sale_coupon_delivery/models/sale_order.py b/addons/sale_coupon_delivery/models/sale_order.py index f24b0082d20..f7762a7256d 100644 --- a/addons/sale_coupon_delivery/models/sale_order.py +++ b/addons/sale_coupon_delivery/models/sale_order.py @@ -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, diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 5a011fda192..f62cfc3742c 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -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 diff --git a/addons/stock/models/stock_rule.py b/addons/stock/models/stock_rule.py index a400738f8b3..624ba668947 100644 --- a/addons/stock/models/stock_rule.py +++ b/addons/stock/models/stock_rule.py @@ -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 = _("
A need is created in %s and a rule will be triggered to fulfill it.") % (source) + suffix = _("
A need is created in %s and a rule will be triggered to fulfill it.", source) if self.procure_method == 'mts_else_mto' and self.location_src_id: suffix = _("
If the products are not available in %s, a rule will be triggered to bring products in this location.", source) message_dict = { - 'pull': _('When products are needed in %s,
%s are created from %s to fulfill the need.') % (destination, operation, source) + suffix, - 'push': _('When products arrive in %s,
%s are created to send them in %s.') % (source, operation, destination) + 'pull': _('When products are needed in %s,
%s are created from %s to fulfill the need.', destination, operation, source) + suffix, + 'push': _('When products arrive in %s,
%s are created to send them in %s.', source, operation, destination) } return message_dict diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index 975a4006265..39c743d96c3 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -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')