Skip to content

Commit

Permalink
Merge pull request #354 from transifex/revert-arb-remove-metadata-in-…
Browse files Browse the repository at this point in the history
…compiled-files

Revert "ARB - remove metadata in the output"
  • Loading branch information
deathbird authored Aug 26, 2024
2 parents c1b0d48 + 7877d1a commit da3e7c2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
27 changes: 2 additions & 25 deletions openformats/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion openformats/tests/formats/arb/files/1_el.arb
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
{
"@@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.} }",
"gold_coins": "{count, plural, zero {el:The chest is empty.} one {el:You have one gold coin.} other {el:You have {cnt} gold coins.}}",
"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/2wCEAAkGBhQGBRUIBwgKFQkKDRYODRYMFhYfHhoWHRweHB8cHh4cJzIqIyUkHB4cITssLycpLCwsFSExPjAtNSgrLEABCQoKDQsNGQ4OGTUkHiQ1LDU1NS4sLCo1NTYpNTYpLCw1NS40NCw0LikuKSkpLCwpL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HgrQQhAlk9QhCBghCEAf/2Q==",
"video": "http://www.youtube.com/user_interaction"
}
}
24 changes: 23 additions & 1 deletion openformats/tests/formats/arb/files/1_en_exported.arb
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
{
"@@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.} }",
"gold_coins": "{count, plural, zero {The chest is empty.} one {You have one gold coin.} other {You have {cnt} gold coins.}}",
"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//EADQQAAEDAgIIAwUJAAAAAAAAAAEAAgMEEQUhBhITMUFRYXEUIjIjgbHB0QcWNEJTkaGi4f/EABgBAAMBAQAAAAAAAAAAAAAAAAABBAUC/8QAIBEAAgEEAgMBAAAAAAAAAAAAAAECAxExQQQhEiKhFP/aAAwDAQACEQMRAD8A7c30+4LN6WSubVwxxyPbYufdhIzyA3dyvtJjTqHFjHKWvpZbOjLbXFsiLjI2cDlvzVPSmobII6mJwLQ19rcxY2PLsmVUINVFddFj7xeGwNz5zeoiadU88sj9f9SfB8VqKOQvmqHSMkiHllPpflmCM7b7hIJ6uSplAkn9kDrFthY24Gwum9LXtqachoIeBmD8QeKWDS/PCEX0nf4OsG0hkmxjYVjmmOa4ZqgDVIBPcg9ei1Nlh8FDY8VbNM6zIgXn9rD+Sr2JaXPjkEVBTN13uDI9oTck7hYfVMhrUPKfotGrQq8DX+HbtpGbXVGvqjK9s7e9epEVjn+k8UmB4trAu8FUv2sd9weR5gOR49R2VeWsGI0oEbgJb2IPG+S6NV0TK+jNPVRNdE8WcHLn+O6DzUFUZMHa99M4ekWLmnkQSLjrv+KT6NCjyY+KUumtmbnqNhUGF5Ie02IKvUkxEJlYPLexKli2D1FDRNrcSpYtj6Ha4zHImxNhwGe9JjWSOpCwgiFxvEQ02yyIHPuk6mmiyNeMkOZMW1W2a4342TvQzAXYhiLcYqmkQwkmC/5iQRcdBc58Sk+iNBTmU1OkNXFZpAhidffzNt/AAZ9eS6w1oa2zQAAMrLq60S8nkNJwis7JoQhBmEW+kdgpWUW+kdgpIAyv2iR+I0dbSkfiayCP+4PyT+sw2PEaXYVdOx0Rys4fDkkOlz9pjNDSfq120PZgv81qBuSWzlN3Yjw/Q6mwup29NS+1YbtL3OdY8wHGwPVPEL1M7cnLLBCEIERb6R2CkhCAKlTA2Sdkj42F8TzsyQLt8h3HgrQQhAlk9QhCBghCEAf/2Q==",
"video": "http://www.youtube.com/user_interaction"
}
}

0 comments on commit da3e7c2

Please sign in to comment.