Fixes a large number of cases where strings are translated then
formatted, instead of letting `_()` do the formatting internally,
which allows it to recover from incorrect translations (missing,
broken, or extra placeholders).
Also
- removes translation markers entirely when there's nothing to
translate e.g. `_("%s - %s")` is not useful
- fixes a few messes which lead to only partial translatability
(DRY is generally a bad idea when translations are involved, even
more so when you don't make the variable part translatable)
- fixes a few nearby issues noticed at the same time
- replaces a few `"%s"` by `%r`, which should automatically quote
strings relatively appropriately
- fixes translated strings which use `\` to escape a newline (in order
to fill-paragraph): `\` escapes only the newline, if the
continuation string is indented this results in a bunch of spaces
ending in the string to translate, which is pretty garbage for the
translator, using implicit concatenation works much better
Note: some of the updates revert f-string parameters to %, because
babel (2.9) apparently has trouble with f-strings and blows up trying
to extract them.
Not in scope:
Helping translators fix translatable strings e.g. any translation
string with more than one placeholder probably should use keyword
placeholders
- Provides more context / data to the translator to make sense of the
sentence.
- Allows reordering the translated terms, which can be necessary
depending on the sentence and language.
closes odoo/odoo#139314
Related: odoo/enterprise#49311
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
41 lines
1.8 KiB
Python
41 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, models, tools, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class DecimalPrecision(models.Model):
|
|
_inherit = 'decimal.precision'
|
|
|
|
@api.constrains('digits')
|
|
def _check_main_currency_rounding(self):
|
|
if any(precision.name == 'Account' and
|
|
tools.float_compare(self.env.company.currency_id.rounding, 10 ** - precision.digits, precision_digits=6) == -1
|
|
for precision in self):
|
|
raise ValidationError(_("You cannot define the decimal precision of 'Account' as greater than the rounding factor of the company's main currency"))
|
|
return True
|
|
|
|
@api.onchange('digits')
|
|
def _onchange_digits(self):
|
|
if self.name != "Product Unit of Measure": # precision_get() relies on this name
|
|
return
|
|
# We are changing the precision of UOM fields; check whether the
|
|
# precision is equal or higher than existing units of measure.
|
|
rounding = 1.0 / 10.0**self.digits
|
|
dangerous_uom = self.env['uom.uom'].search([('rounding', '<', rounding)])
|
|
if dangerous_uom:
|
|
uom_descriptions = [
|
|
" - %s (id=%s, precision=%s)" % (uom.name, uom.id, uom.rounding)
|
|
for uom in dangerous_uom
|
|
]
|
|
return {'warning': {
|
|
'title': _('Warning!'),
|
|
'message': _(
|
|
"You are setting a Decimal Accuracy less precise than the UOMs:\n"
|
|
"%s\n"
|
|
"This may cause inconsistencies in computations.\n"
|
|
"Please increase the rounding of those units of measure, or the digits of this Decimal Accuracy.",
|
|
'\n'.join(uom_descriptions)),
|
|
}}
|