Skip to content

Commit 7877d1a

Browse files
committed
Revert "ARB - remove metadata in the output"
This reverts commit 518145a.
1 parent c1b0d48 commit 7877d1a

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

openformats/formats/json.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ def _replace_translations(self, template, stringset, is_real_stringset):
264264
self.stringset = stringset
265265
self.stringset_index = 0
266266

267-
self.depth = 0
268267
self.metadata_blocks = []
269268

270269
parsed = DumbJson(template)
@@ -279,8 +278,7 @@ def _insert(self, parsed, is_real_stringset):
279278
elif parsed.type == list:
280279
return self._insert_from_list(parsed, is_real_stringset)
281280

282-
def _insert_item(self, value, value_position, is_real_stringset, key_position=0):
283-
281+
def _insert_item(self, value, value_position, is_real_stringset):
284282
at_least_one = False
285283

286284
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)
320318
self._insert_regular_string(value, value_position, "", False)
321319

322320
elif isinstance(value, DumbJson):
323-
self.depth += 1
324-
if self.depth == 1:
325-
self.metadata_blocks.append((key_position - 1, value.end + 1))
326321
items_still_left = self._insert(value, is_real_stringset)
327322

328323
if not items_still_left:
329324
self._copy_until_and_remove_section(value.end + 1)
330-
self.depth -= 1
331325
else:
332326
at_least_one = True
333327

@@ -355,7 +349,7 @@ def _insert_from_dict(self, parsed, is_real_stringset):
355349
self.transcriber.mark_section_start()
356350

357351
tmp_at_least_one = self._insert_item(
358-
value, value_position, is_real_stringset, key_position
352+
value, value_position, is_real_stringset
359353
)
360354

361355
if tmp_at_least_one:
@@ -630,24 +624,7 @@ def compile(self, template, stringset, language_info=None, **kwargs):
630624
for openstring in stringset
631625
]
632626
new_template = self._replace_translations(template, fake_stringset, False)
633-
num_of_mdb = len(self.metadata_blocks)
634-
while num_of_mdb > 0:
635-
idx = num_of_mdb - 1
636-
new_template = "{}{}".format(
637-
new_template[: self.metadata_blocks[idx][0]],
638-
new_template[self.metadata_blocks[idx][1] :],
639-
)
640-
num_of_mdb -= 1
641-
642-
# Remember whether the root JSON ends with "}" on a separate line
643-
closed_on_new_line = new_template[new_template.rfind("}") - 1] == "\n"
644-
645627
new_template = self._clean_empties(new_template)
646-
end_of_root_json = new_template.rfind("}")
647-
if closed_on_new_line and new_template[end_of_root_json - 1] != "\n":
648-
new_template = "{}{}{}".format(
649-
new_template[:end_of_root_json], "\n", new_template[end_of_root_json:]
650-
)
651628

652629
if language_info is not None:
653630
match = re.search(r"(\"@@locale\"\s*:\s*\")([A-Z_a-z]*)\"", new_template)
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
{
22
"@@locale": "en_US",
3+
"@@x-template": "path/to/template.arb",
4+
"@@context": "HomePage",
35

46
"MSG_OK": "el:Everything works fine.",
57

68
"title_bar": "el:My Cool Home",
9+
"@title_bar": {
10+
"type": "text",
11+
"context": "HomePage",
12+
"description": "Page title."
13+
},
714

815
"total_files": "{ item_count, plural, one {el:You have {file_count} file.} other {el:You have {file_count} files.} }",
916
"special_chars": "{ cnt, plural, one {el:This is Sam's book.} other {el:These are Sam's books.} }",
1017
"gold_coins": "{count, plural, zero {el:The chest is empty.} one {el:You have one gold coin.} other {el:You have {cnt} gold coins.}}",
1118
"custom_plural_value": "{number, plural, one {el:1 New} two {el:# New}}",
1219

1320
"logo@src": "images/001.jpg",
21+
"@logo@src": {
22+
"context": "arb_editor",
23+
"type": "image",
24+
"description": "logo image, 128x128"
25+
},
1426

1527
"font_style": "#title {font-family: Verdana, Geneva, sans-serif; font-style: oblique; font-size: 36px}",
28+
"@font_style": {
29+
"context": "arb_editor",
30+
"type": "css",
31+
"description": "font specific css"
32+
},
1633

1734
"input_test1@placeholder": "el:localized placeholder text",
1835
"input_test2@value": "el:localized input value",
1936

20-
"logo": "el:ARB"
37+
"logo": "el:ARB",
38+
"@logo": {
39+
"type": "text",
40+
"screen": "data:image/jpeg;base64,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NJwis7JoQhBmEW+kdgpWUW+kdgpIAyv2iR+I0dbSkfiayCP+4PyT+sw2PEaXYVdOx0Rys4fDkkOlz9pjNDSfq120PZgv81qBuSWzlN3Yjw/Q6mwup29NS+1YbtL3OdY8wHGwPVPEL1M7cnLLBCEIERb6R2CkhCAKlTA2Sdkj42F8TzsyQLt8h3HgrQQhAlk9QhCBghCEAf/2Q==",
41+
"video": "http://www.youtube.com/user_interaction"
42+
}
2143
}
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
{
22
"@@locale": "en_US",
3+
"@@x-template": "path/to/template.arb",
4+
"@@context": "HomePage",
35

46
"MSG_OK": "Everything works fine.",
57

68
"title_bar": "My Cool Home",
9+
"@title_bar": {
10+
"type": "text",
11+
"context": "HomePage",
12+
"description": "Page title."
13+
},
714

815
"total_files": "{ item_count, plural, one {You have {file_count} file.} other {You have {file_count} files.} }",
916
"special_chars": "{ cnt, plural, one {This is Sam's book.} other {These are Sam's books.} }",
1017
"gold_coins": "{count, plural, zero {The chest is empty.} one {You have one gold coin.} other {You have {cnt} gold coins.}}",
1118
"custom_plural_value": "{number, plural, one {1 New} two {# New}}",
1219

1320
"logo@src": "images/001.jpg",
21+
"@logo@src": {
22+
"context": "arb_editor",
23+
"type": "image",
24+
"description": "logo image, 128x128"
25+
},
1426

1527
"font_style": "#title {font-family: Verdana, Geneva, sans-serif; font-style: oblique; font-size: 36px}",
28+
"@font_style": {
29+
"context": "arb_editor",
30+
"type": "css",
31+
"description": "font specific css"
32+
},
1633

1734
"input_test1@placeholder": "localized placeholder text",
1835
"input_test2@value": "localized input value",
1936

20-
"logo": "ARB"
37+
"logo": "ARB",
38+
"@logo": {
39+
"type": "text",
40+
"screen": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBhQGBRUIBwgKFQkKDRYODRYMFhYfHhoWHRweHB8cHh4cJzIqIyUkHB4cITssLycpLCwsFSExPjAtNSgrL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