From 7877d1a8b1c3240a416fc69c661e774161bd7ba8 Mon Sep 17 00:00:00 2001 From: Jack Dimas Date: Fri, 23 Aug 2024 12:48:28 +0300 Subject: [PATCH] Revert "ARB - remove metadata in the output" This reverts commit 518145a9229c0eb7b06dbc97c3658f542fb5ae53. --- openformats/formats/json.py | 27 ++----------------- openformats/tests/formats/arb/files/1_el.arb | 24 ++++++++++++++++- .../tests/formats/arb/files/1_en_exported.arb | 24 ++++++++++++++++- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/openformats/formats/json.py b/openformats/formats/json.py index 6679139d..e988133a 100644 --- a/openformats/formats/json.py +++ b/openformats/formats/json.py @@ -264,7 +264,6 @@ def _replace_translations(self, template, stringset, is_real_stringset): self.stringset = stringset self.stringset_index = 0 - self.depth = 0 self.metadata_blocks = [] parsed = DumbJson(template) @@ -279,8 +278,7 @@ def _insert(self, parsed, is_real_stringset): elif parsed.type == list: return self._insert_from_list(parsed, is_real_stringset) - def _insert_item(self, value, value_position, is_real_stringset, key_position=0): - + def _insert_item(self, value, value_position, is_real_stringset): at_least_one = False if isinstance(value, (six.binary_type, six.text_type)): @@ -320,14 +318,10 @@ def _insert_item(self, value, value_position, is_real_stringset, key_position=0) self._insert_regular_string(value, value_position, "", False) elif isinstance(value, DumbJson): - self.depth += 1 - if self.depth == 1: - self.metadata_blocks.append((key_position - 1, value.end + 1)) items_still_left = self._insert(value, is_real_stringset) if not items_still_left: self._copy_until_and_remove_section(value.end + 1) - self.depth -= 1 else: at_least_one = True @@ -355,7 +349,7 @@ def _insert_from_dict(self, parsed, is_real_stringset): self.transcriber.mark_section_start() tmp_at_least_one = self._insert_item( - value, value_position, is_real_stringset, key_position + value, value_position, is_real_stringset ) if tmp_at_least_one: @@ -630,24 +624,7 @@ def compile(self, template, stringset, language_info=None, **kwargs): for openstring in stringset ] new_template = self._replace_translations(template, fake_stringset, False) - num_of_mdb = len(self.metadata_blocks) - while num_of_mdb > 0: - idx = num_of_mdb - 1 - new_template = "{}{}".format( - new_template[: self.metadata_blocks[idx][0]], - new_template[self.metadata_blocks[idx][1] :], - ) - num_of_mdb -= 1 - - # Remember whether the root JSON ends with "}" on a separate line - closed_on_new_line = new_template[new_template.rfind("}") - 1] == "\n" - new_template = self._clean_empties(new_template) - end_of_root_json = new_template.rfind("}") - if closed_on_new_line and new_template[end_of_root_json - 1] != "\n": - new_template = "{}{}{}".format( - new_template[:end_of_root_json], "\n", new_template[end_of_root_json:] - ) if language_info is not None: match = re.search(r"(\"@@locale\"\s*:\s*\")([A-Z_a-z]*)\"", new_template) diff --git a/openformats/tests/formats/arb/files/1_el.arb b/openformats/tests/formats/arb/files/1_el.arb index 4589e572..59ee823d 100644 --- a/openformats/tests/formats/arb/files/1_el.arb +++ b/openformats/tests/formats/arb/files/1_el.arb @@ -1,9 +1,16 @@ { "@@locale": "en_US", + "@@x-template": "path/to/template.arb", + "@@context": "HomePage", "MSG_OK": "el:Everything works fine.", "title_bar": "el:My Cool Home", + "@title_bar": { + "type": "text", + "context": "HomePage", + "description": "Page title." + }, "total_files": "{ item_count, plural, one {el:You have {file_count} file.} other {el:You have {file_count} files.} }", "special_chars": "{ cnt, plural, one {el:This is Sam's book.} other {el:These are Sam's books.} }", @@ -11,11 +18,26 @@ "custom_plural_value": "{number, plural, one {el:1 New} two {el:# New}}", "logo@src": "images/001.jpg", + "@logo@src": { + "context": "arb_editor", + "type": "image", + "description": "logo image, 128x128" + }, "font_style": "#title {font-family: Verdana, Geneva, sans-serif; font-style: oblique; font-size: 36px}", + "@font_style": { + "context": "arb_editor", + "type": "css", + "description": "font specific css" + }, "input_test1@placeholder": "el:localized placeholder text", "input_test2@value": "el:localized input value", - "logo": "el:ARB" + "logo": "el:ARB", + "@logo": { + "type": "text", + "screen": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBhQGBRUIBwgKFQkKDRYODRYMFhYfHhoWHRweHB8cHh4cJzIqIyUkHB4cITssLycpLCwsFSExPjAtNSgrLE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NS+1YbtL3OdY8wHGwPVPEL1M7cnLLBCEIERb6R2CkhCAKlTA2Sdkj42F8TzsyQLt8h3HgrQQhAlk9QhCBghCEAf/2Q==", + "video": "http://www.youtube.com/user_interaction" + } } \ No newline at end of file diff --git a/openformats/tests/formats/arb/files/1_en_exported.arb b/openformats/tests/formats/arb/files/1_en_exported.arb index b0921f01..6673e571 100644 --- a/openformats/tests/formats/arb/files/1_en_exported.arb +++ b/openformats/tests/formats/arb/files/1_en_exported.arb @@ -1,9 +1,16 @@ { "@@locale": "en_US", + "@@x-template": "path/to/template.arb", + "@@context": "HomePage", "MSG_OK": "Everything works fine.", "title_bar": "My Cool Home", + "@title_bar": { + "type": "text", + "context": "HomePage", + "description": "Page title." + }, "total_files": "{ item_count, plural, one {You have {file_count} file.} other {You have {file_count} files.} }", "special_chars": "{ cnt, plural, one {This is Sam's book.} other {These are Sam's books.} }", @@ -11,11 +18,26 @@ "custom_plural_value": "{number, plural, one {1 New} two {# New}}", "logo@src": "images/001.jpg", + "@logo@src": { + "context": "arb_editor", + "type": "image", + "description": "logo image, 128x128" + }, "font_style": "#title {font-family: Verdana, Geneva, sans-serif; font-style: oblique; font-size: 36px}", + "@font_style": { + "context": "arb_editor", + "type": "css", + "description": "font specific css" + }, "input_test1@placeholder": "localized placeholder text", "input_test2@value": "localized input value", - "logo": "ARB" + "logo": "ARB", + "@logo": { + "type": "text", + "screen": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBhQGBRUIBwgKFQkKDRYODRYMFhYfHhoWHRweHB8cHh4cJzIqIyUkHB4cITssLycpLCwsFSExPjAtNSgrLEABCQoKDQsNGQ4OGTUkHiQ1LDU1NS4sLCo1NTYpNTYpLCw1NS40NCw0LikuKSkpLCwpLCw0KTQpKSwsNCkpNCkpLP/AABEIADIAMgMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAAABQIEBgcBA//EADQQAAEDAgIIAwUJAAAAAAAAAAEAAgMEE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