Do not replace values before passing to gettext

master
Salvo 'LtWorf' Tomaselli 2020-10-24 18:23:59 +07:00
parent 750f123620
commit 81cc446b90
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF
6 changed files with 17 additions and 17 deletions

@ -332,28 +332,28 @@ def parse_tokens(expression: List[Union[list, str]]) -> Node:
if len(expression[:i]) == 0:
raise ParserException(
_(f'Expected left operand for {expression[i]!r}'))
_('Expected left operand for %s') % repr(expression[i]))
if len(expression[i + 1:]) == 0:
raise ParserException(
_(f'Expected right operand for {expression[i]!r}'))
_('Expected right operand for %s') % repr(expression[i]))
return Binary(expression[i], parse_tokens(expression[:i]), parse_tokens(expression[i + 1:])) # type: ignore
'''Searches for unary operators, parsing from right to left'''
for i in range(len(expression)):
if expression[i] in u_operators: # Unary operator
if len(expression) <= i + 2:
raise ParserException(
_(f'Expected more tokens in {expression[i]!r}'))
_('Expected more tokens in %s') % repr(expression[i]))
elif len(expression) > i + 3:
raise ParserException(
_(f'Too many tokens in {expression[i]!r}'))
_('Too many tokens in %s') % repr(expression[i]))
return Unary(
expression[i], # type: ignore
prop=expression[1 + i].strip(), # type: ignore
child=parse_tokens(expression[2 + i]) # type: ignore
)
raise ParserException(_(f'Parse error on {expression!r}'))
raise ParserException(_('Parse error on %s') % repr(expression))
def _find_matching_parenthesis(expression: str, start=0, openpar='(', closepar=')') -> Optional[int]:
@ -423,7 +423,7 @@ def tokenize(expression: str) -> list:
end = _find_matching_parenthesis(expression)
if end is None:
raise TokenizerException(
_(f'Missing matching \')\' in \'{expression}\''))
_('Missing matching \')\' in \'%s\'') % expression)
# Appends the tokenization of the content of the parenthesis
items.append(tokenize(expression[1:end]))
# Removes the entire parentesis and content from the expression

@ -89,7 +89,7 @@ class Relation:
content = []
for row in loaded['content']:
if len(row) != len(header):
raise ValueError(_(f'Line {row} contains an incorrect amount of values'))
raise ValueError(_('Line %d contains an incorrect amount of values') % row)
t_row: Tuple[Optional[Union[int, float, str, Rdate]], ...] = load(
row,
Tuple[Optional[Union[int, float, str, Rdate]], ...], # type: ignore
@ -137,7 +137,7 @@ class Relation:
for row in content:
if len(row) != len(header):
raise ValueError(_(f'Line {row} contains an incorrect amount of values'))
raise ValueError(_('Line %d contains an incorrect amount of values') % row)
r_content.append(row)
# Guess types
@ -181,7 +181,7 @@ class Relation:
try:
c_expr = compile(expr, 'selection', 'eval')
except:
raise Exception(_(f'Failed to compile expression: {expr}'))
raise Exception(_('Failed to compile expression: %s') % expr)
content = []
for i in self.content:
@ -194,7 +194,7 @@ class Relation:
if eval(c_expr, attributes):
content.append(i)
except Exception as e:
raise Exception(_(f'Failed to evaluate {expr} with {i}\n{e}'))
raise Exception(_('Failed to evaluate {expr} with {i}\n{e}').format(expr=expr, i=i, e=e))
return Relation(self.header, frozenset(content))
def product(self, other: 'Relation') -> 'Relation':
@ -473,7 +473,7 @@ class Header(tuple):
for i in self:
if not is_valid_relation_name(i):
raise Exception(_(f'"{i}" is not a valid attribute name'))
raise Exception(_('"%s" is not a valid attribute name') % i)
if len(self) != len(set(self)):
raise Exception('Attribute names must be unique')
@ -489,12 +489,12 @@ class Header(tuple):
attrs = list(self)
for old, new in params.items():
if not is_valid_relation_name(new):
raise Exception(_(f'{new} is not a valid attribute name'))
raise Exception(_('%s is not a valid attribute name') % new)
try:
id_ = attrs.index(old)
attrs[id_] = new
except:
raise Exception(_(f'Field not found: {old}'))
raise Exception(_('Field not found: %s') % old)
return Header(attrs)
def sharedAttributes(self, other: 'Header') -> int:

@ -84,7 +84,7 @@ class Rdate:
'''date: A string representing a date YYYY-MM-DD'''
r = _date_regexp.match(date)
if not r:
raise ValueError(_(f'{date} is not a valid date'))
raise ValueError(_('%s is not a valid date') % date)
year = int(r.group(1))
month = int(r.group(3))

@ -99,7 +99,7 @@ class creatorForm(QtWidgets.QDialog):
try:
hlist.append(self.table.item(i, j).text())
except:
QtWidgets.QMessageBox.information(None, _("Error"), _(f'Unset value in {i + 1},{j + 1}!'))
QtWidgets.QMessageBox.information(None, _("Error"), _('Unset value in %d,%d!') % (i + 1, j + 1))
return None
content.append(hlist)
return relation.Relation.create_from(header, content)

@ -118,7 +118,7 @@ class relForm(QtWidgets.QMainWindow):
if online is None:
r = _('Network error')
elif online > version:
r = _(f'New version available online: {online}.')
r = _('New version available online: %s.') % online
elif online == version:
r = _('Latest version installed.')
else:

@ -123,7 +123,7 @@ def load_relation(filename: str, defname: Optional[str]) -> Optional[str]:
'''
if not os.path.isfile(filename):
print(colorize(
_(f'{filename} is not a file'), ERROR_COLOR), file=sys.stderr)
_('%s is not a file') % filename, ERROR_COLOR), file=sys.stderr)
return None
if defname is None: