Do not replace values before passing to gettext
This commit is contained in:
parent
750f123620
commit
81cc446b90
@ -332,28 +332,28 @@ def parse_tokens(expression: List[Union[list, str]]) -> Node:
|
|||||||
|
|
||||||
if len(expression[:i]) == 0:
|
if len(expression[:i]) == 0:
|
||||||
raise ParserException(
|
raise ParserException(
|
||||||
_(f'Expected left operand for {expression[i]!r}'))
|
_('Expected left operand for %s') % repr(expression[i]))
|
||||||
|
|
||||||
if len(expression[i + 1:]) == 0:
|
if len(expression[i + 1:]) == 0:
|
||||||
raise ParserException(
|
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
|
return Binary(expression[i], parse_tokens(expression[:i]), parse_tokens(expression[i + 1:])) # type: ignore
|
||||||
'''Searches for unary operators, parsing from right to left'''
|
'''Searches for unary operators, parsing from right to left'''
|
||||||
for i in range(len(expression)):
|
for i in range(len(expression)):
|
||||||
if expression[i] in u_operators: # Unary operator
|
if expression[i] in u_operators: # Unary operator
|
||||||
if len(expression) <= i + 2:
|
if len(expression) <= i + 2:
|
||||||
raise ParserException(
|
raise ParserException(
|
||||||
_(f'Expected more tokens in {expression[i]!r}'))
|
_('Expected more tokens in %s') % repr(expression[i]))
|
||||||
elif len(expression) > i + 3:
|
elif len(expression) > i + 3:
|
||||||
raise ParserException(
|
raise ParserException(
|
||||||
_(f'Too many tokens in {expression[i]!r}'))
|
_('Too many tokens in %s') % repr(expression[i]))
|
||||||
|
|
||||||
return Unary(
|
return Unary(
|
||||||
expression[i], # type: ignore
|
expression[i], # type: ignore
|
||||||
prop=expression[1 + i].strip(), # type: ignore
|
prop=expression[1 + i].strip(), # type: ignore
|
||||||
child=parse_tokens(expression[2 + i]) # 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]:
|
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)
|
end = _find_matching_parenthesis(expression)
|
||||||
if end is None:
|
if end is None:
|
||||||
raise TokenizerException(
|
raise TokenizerException(
|
||||||
_(f'Missing matching \')\' in \'{expression}\''))
|
_('Missing matching \')\' in \'%s\'') % expression)
|
||||||
# Appends the tokenization of the content of the parenthesis
|
# Appends the tokenization of the content of the parenthesis
|
||||||
items.append(tokenize(expression[1:end]))
|
items.append(tokenize(expression[1:end]))
|
||||||
# Removes the entire parentesis and content from the expression
|
# Removes the entire parentesis and content from the expression
|
||||||
|
@ -89,7 +89,7 @@ class Relation:
|
|||||||
content = []
|
content = []
|
||||||
for row in loaded['content']:
|
for row in loaded['content']:
|
||||||
if len(row) != len(header):
|
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(
|
t_row: Tuple[Optional[Union[int, float, str, Rdate]], ...] = load(
|
||||||
row,
|
row,
|
||||||
Tuple[Optional[Union[int, float, str, Rdate]], ...], # type: ignore
|
Tuple[Optional[Union[int, float, str, Rdate]], ...], # type: ignore
|
||||||
@ -137,7 +137,7 @@ class Relation:
|
|||||||
|
|
||||||
for row in content:
|
for row in content:
|
||||||
if len(row) != len(header):
|
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)
|
r_content.append(row)
|
||||||
|
|
||||||
# Guess types
|
# Guess types
|
||||||
@ -181,7 +181,7 @@ class Relation:
|
|||||||
try:
|
try:
|
||||||
c_expr = compile(expr, 'selection', 'eval')
|
c_expr = compile(expr, 'selection', 'eval')
|
||||||
except:
|
except:
|
||||||
raise Exception(_(f'Failed to compile expression: {expr}'))
|
raise Exception(_('Failed to compile expression: %s') % expr)
|
||||||
|
|
||||||
content = []
|
content = []
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
@ -194,7 +194,7 @@ class Relation:
|
|||||||
if eval(c_expr, attributes):
|
if eval(c_expr, attributes):
|
||||||
content.append(i)
|
content.append(i)
|
||||||
except Exception as e:
|
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))
|
return Relation(self.header, frozenset(content))
|
||||||
|
|
||||||
def product(self, other: 'Relation') -> 'Relation':
|
def product(self, other: 'Relation') -> 'Relation':
|
||||||
@ -473,7 +473,7 @@ class Header(tuple):
|
|||||||
|
|
||||||
for i in self:
|
for i in self:
|
||||||
if not is_valid_relation_name(i):
|
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)):
|
if len(self) != len(set(self)):
|
||||||
raise Exception('Attribute names must be unique')
|
raise Exception('Attribute names must be unique')
|
||||||
@ -489,12 +489,12 @@ class Header(tuple):
|
|||||||
attrs = list(self)
|
attrs = list(self)
|
||||||
for old, new in params.items():
|
for old, new in params.items():
|
||||||
if not is_valid_relation_name(new):
|
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:
|
try:
|
||||||
id_ = attrs.index(old)
|
id_ = attrs.index(old)
|
||||||
attrs[id_] = new
|
attrs[id_] = new
|
||||||
except:
|
except:
|
||||||
raise Exception(_(f'Field not found: {old}'))
|
raise Exception(_('Field not found: %s') % old)
|
||||||
return Header(attrs)
|
return Header(attrs)
|
||||||
|
|
||||||
def sharedAttributes(self, other: 'Header') -> int:
|
def sharedAttributes(self, other: 'Header') -> int:
|
||||||
|
@ -84,7 +84,7 @@ class Rdate:
|
|||||||
'''date: A string representing a date YYYY-MM-DD'''
|
'''date: A string representing a date YYYY-MM-DD'''
|
||||||
r = _date_regexp.match(date)
|
r = _date_regexp.match(date)
|
||||||
if not r:
|
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))
|
year = int(r.group(1))
|
||||||
month = int(r.group(3))
|
month = int(r.group(3))
|
||||||
|
@ -99,7 +99,7 @@ class creatorForm(QtWidgets.QDialog):
|
|||||||
try:
|
try:
|
||||||
hlist.append(self.table.item(i, j).text())
|
hlist.append(self.table.item(i, j).text())
|
||||||
except:
|
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
|
return None
|
||||||
content.append(hlist)
|
content.append(hlist)
|
||||||
return relation.Relation.create_from(header, content)
|
return relation.Relation.create_from(header, content)
|
||||||
|
@ -118,7 +118,7 @@ class relForm(QtWidgets.QMainWindow):
|
|||||||
if online is None:
|
if online is None:
|
||||||
r = _('Network error')
|
r = _('Network error')
|
||||||
elif online > version:
|
elif online > version:
|
||||||
r = _(f'New version available online: {online}.')
|
r = _('New version available online: %s.') % online
|
||||||
elif online == version:
|
elif online == version:
|
||||||
r = _('Latest version installed.')
|
r = _('Latest version installed.')
|
||||||
else:
|
else:
|
||||||
|
@ -123,7 +123,7 @@ def load_relation(filename: str, defname: Optional[str]) -> Optional[str]:
|
|||||||
'''
|
'''
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
print(colorize(
|
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
|
return None
|
||||||
|
|
||||||
if defname is None:
|
if defname is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user