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 /odoo/models.py | |
| 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 'odoo/models.py')
| -rw-r--r-- | odoo/models.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/odoo/models.py b/odoo/models.py index 397d13f2691..1ab766d9b07 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -991,7 +991,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): # broken transaction, exit and hope the source error was already logged if not any(message['type'] == 'error' for message in messages): info = data_list[0]['info'] - messages.append(dict(info, type='error', message=_(u"Unknown database error: '%s'") % e)) + messages.append(dict(info, type='error', message=_(u"Unknown database error: '%s'", e))) return except Exception: pass @@ -1188,7 +1188,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): type='error', record=stream.index, field='.id', - message=_(u"Unknown database identifier '%s'") % dbid)) + message=_(u"Unknown database identifier '%s'", dbid))) dbid = False converted = convert(record, functools.partial(_log, extras, stream.index)) @@ -1442,7 +1442,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): self._fields, 'date_stop'): if not set_first_of(["date_delay", "planned_hours", "x_date_delay", "x_planned_hours"], self._fields, 'date_delay'): - raise UserError(_("Insufficient fields to generate a Calendar View for %s, missing a date_stop or a date_delay") % self._name) + raise UserError(_("Insufficient fields to generate a Calendar View for %s, missing a date_stop or a date_delay", self._name)) return view @@ -1521,7 +1521,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): result['type'] = view_type result['name'] = 'default' except AttributeError: - raise UserError(_("No default view of type '%s' could be found !") % view_type) + raise UserError(_("No default view of type '%s' could be found !", view_type)) return result @api.model @@ -2221,7 +2221,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): match = regex_field_agg.match(fspec) if not match: - raise UserError(_("Invalid field specification %r.") % fspec) + raise UserError(_("Invalid field specification %r.", fspec)) name, func, fname = match.groups() if func: @@ -2231,9 +2231,9 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): if not field: raise ValueError("Invalid field %r on model %r" % (fname, self._name)) if not (field.base_field.store and field.base_field.column_type): - raise UserError(_("Cannot aggregate field %r.") % fname) + raise UserError(_("Cannot aggregate field %r.", fname)) if func not in VALID_AGGREGATE_FUNCTIONS: - raise UserError(_("Invalid aggregation function %r.") % func) + raise UserError(_("Invalid aggregation function %r.", func)) else: # we have 'name', retrieve the aggregator on the field field = self._fields.get(name) @@ -2249,7 +2249,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): if fname in groupby_fields: continue if name in aggregated_fields: - raise UserError(_("Output name %r is used twice.") % name) + raise UserError(_("Output name %r is used twice.", name)) aggregated_fields.append(name) expr = self._inherits_join_calc(self._table, fname, query) @@ -3657,7 +3657,7 @@ Record ids: %(records)s cr.execute(query, params + [sub_ids]) if cr.rowcount != len(sub_ids): raise MissingError( - _('One of the records you are trying to modify has already been deleted (Document type: %s).') % self._description + _('One of the records you are trying to modify has already been deleted (Document type: %s).', self._description) + '\n\n({} {}, {} {})'.format(_('Records:'), sub_ids[:6], _('User:'), self._uid) ) |
