From 81cc446b90e6fb42888ff6468d00530aa52e68a5 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Sat, 24 Oct 2020 18:23:59 +0200 Subject: [PATCH] Do not replace values before passing to gettext --- relational/parser.py | 12 ++++++------ relational/relation.py | 14 +++++++------- relational/rtypes.py | 2 +- relational_gui/creator.py | 2 +- relational_gui/guihandler.py | 2 +- relational_readline/linegui.py | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/relational/parser.py b/relational/parser.py index 2bc1f26..98a1cf6 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -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 diff --git a/relational/relation.py b/relational/relation.py index 10c4c4c..96bf0d7 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -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: diff --git a/relational/rtypes.py b/relational/rtypes.py index 69944a3..7281647 100644 --- a/relational/rtypes.py +++ b/relational/rtypes.py @@ -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)) diff --git a/relational_gui/creator.py b/relational_gui/creator.py index d783c8b..437df0e 100644 --- a/relational_gui/creator.py +++ b/relational_gui/creator.py @@ -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) diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index d8ba220..d3c4a9c 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -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: diff --git a/relational_readline/linegui.py b/relational_readline/linegui.py index 38b8f80..7e945b3 100644 --- a/relational_readline/linegui.py +++ b/relational_readline/linegui.py @@ -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: