From d90a0c006613a0a3747bbac64caa8a05a2384e19 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 4 Nov 2024 12:02:46 +0100 Subject: [PATCH] fix(36): format 1.0: suffix attribut must works --- locale/rougail.pot | 10 ++-- src/rougail/convert.py | 97 ++++++++++++++++++++++--------------- src/rougail/object_model.py | 1 + 3 files changed, 65 insertions(+), 43 deletions(-) diff --git a/locale/rougail.pot b/locale/rougail.pot index 7355b7701..97b5a7ede 100644 --- a/locale/rougail.pot +++ b/locale/rougail.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2024-11-01 11:05+0100\n" +"POT-Creation-Date: 2024-11-04 12:04+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -67,19 +67,19 @@ msgstr "" msgid "the variable \"{0}\" has an unvalid default value \"{1}\" should be in {2}" msgstr "" -#: src/rougail/convert.py:265 +#: src/rougail/convert.py:281 msgid "A variable or a family located in the \"{0}\" namespace shall not be used in the \"{1}\" namespace" msgstr "" -#: src/rougail/convert.py:459 +#: src/rougail/convert.py:475 msgid "unknown type {0} for {1}" msgstr "" -#: src/rougail/convert.py:1324 +#: src/rougail/convert.py:1345 msgid "duplicate dictionary file name {0}" msgstr "" -#: src/rougail/convert.py:1371 +#: src/rougail/convert.py:1392 msgid "Cannot execute annotate multiple time" msgstr "" diff --git a/src/rougail/convert.py b/src/rougail/convert.py index aae1a88a2..69bbeaa94 100644 --- a/src/rougail/convert.py +++ b/src/rougail/convert.py @@ -162,45 +162,61 @@ class Paths: path = get_realpath(path, identifier_path) dynamic = None # version 1.0 - if ( - version == "1.0" - and not path in self._data - and "{{ identifier }}" not in path - ): - new_path = None - current_path = None - for name in path.split("."): - parent_path = current_path - if current_path: - current_path += "." + name - else: - current_path = name - if current_path in self._data: - if new_path: - new_path += "." + name + if version == "1.0": + if not path in self._data and "{{ suffix }}" not in path: + new_path = None + current_path = None + identifiers = [] + for name in path.split("."): + parent_path = current_path + if current_path: + current_path += "." + name else: - new_path = name - continue - for dynamic_path in self._dynamics: - if "." in dynamic_path: - parent_dynamic, name_dynamic = dynamic_path.rsplit(".", 1) - else: - parent_dynamic = None - name_dynamic = dynamic_path - if ( - parent_dynamic == parent_path - and name_dynamic.endswith("{{ identifier }}") - and name == name_dynamic.replace("{{ identifier }}", "") - ): - new_path += "." + name_dynamic + current_path = name + if current_path in self._data: + if new_path: + new_path += "." + name + else: + new_path = name + continue + for dynamic_path in self._dynamics: + if "." in dynamic_path: + parent_dynamic, name_dynamic = dynamic_path.rsplit(".", 1) + else: + parent_dynamic = None + name_dynamic = dynamic_path + if ( + parent_dynamic == parent_path + and name_dynamic.endswith("{{ identifier }}") + and name == name_dynamic.replace("{{ identifier }}", "") + ): + new_path += "." + name_dynamic + break + regexp = "^" + name_dynamic.replace("{{ identifier }}", "(.*)") + finded = findall(regexp, name) + if len(finded) != 1 or not finded[0]: + continue + if finded[0] == "{{ identifier }}": + identifiers.append(None) + else: + identifiers.append(finded[0]) + if new_path is None: + new_path = name_dynamic + else: + new_path += "." + name_dynamic + parent_path = dynamic_path break - else: - if new_path: - new_path += "." + name else: - new_path = name - path = new_path - if version != "1.0" and not path in self._data: + if new_path: + new_path += "." + name + else: + new_path = name + path = new_path + else: + identifiers = None + if "{{ suffix }}" in path: + path = path.replace("{{ suffix }}", "{{ identifier }}") + elif not path in self._data: current_path = None parent_path = None new_path = current_path @@ -632,14 +648,17 @@ class ParserVariable: family_obj["type"] = obj_type = "dynamic" if obj_type == "dynamic": family_is_dynamic = True - parent_dynamic = path if "{{ identifier }}" not in name: - if "variable" in family_obj: + if version == "1.0" and "{{ suffix }}" in name: + name = name.replace("{{ suffix }}", "{{ identifier }}") + path = path.replace("{{ suffix }}", "{{ identifier }}") + elif "variable" in family_obj: name += "{{ identifier }}" path += "{{ identifier }}" else: msg = f'dynamic family name must have "{{{{ identifier }}}}" in his name for "{path}"' raise DictConsistencyError(msg, 13, [filename]) + parent_dynamic = path if version != "1.0" and not family_obj and comment: family_obj["description"] = comment self.add_family( @@ -1099,6 +1118,8 @@ class ParserVariable: "type": "any", } else: + if version == "1.0" and val["type"] == "suffix": + val["type"] = "identifier" param_typ = val["type"] val["key"] = key val["path"] = path diff --git a/src/rougail/object_model.py b/src/rougail/object_model.py index da9a753fd..79e637dad 100644 --- a/src/rougail/object_model.py +++ b/src/rougail/object_model.py @@ -687,6 +687,7 @@ CALCULATION_TYPES = { "variable": VariableCalculation, "information": InformationCalculation, "identifier": IdentifierCalculation, + "suffix": IdentifierCalculation, "index": IndexCalculation, } CALCULATION_PROPERTY_TYPES = { -- 2.45.0