Skip to content

Commit

Permalink
Preserve developer comments while compiling ARB files
Browse files Browse the repository at this point in the history
  • Loading branch information
arisktfx committed Aug 22, 2024
1 parent c1b0d48 commit 92b749d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion openformats/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,13 @@ def compile(self, template, stringset, language_info=None, **kwargs):
num_of_mdb = len(self.metadata_blocks)
while num_of_mdb > 0:
idx = num_of_mdb - 1
new_template = "{}{}".format(
new_template = "{}{}{}".format(
new_template[: self.metadata_blocks[idx][0]],
self._preserve_developer_comment(
new_template[
self.metadata_blocks[idx][0] : self.metadata_blocks[idx][1]
]
),
new_template[self.metadata_blocks[idx][1] :],
)
num_of_mdb -= 1
Expand All @@ -660,6 +665,22 @@ def compile(self, template, stringset, language_info=None, **kwargs):

return self._replace_translations(new_template, stringset, True)

def _preserve_developer_comment(self, template_part):
if "description" in template_part:
template_part_to_dict = json.loads(f"{{{template_part}}}")
part_values = list(template_part_to_dict.values())[0]
if len(part_values.keys()) == 1 and part_values.get("description"):
# it only contains a non empty description
return template_part
description_value = part_values.get("description")
if description_value:
# it only contains multiple values, keep only the description
template_part_key = list(template_part_to_dict.keys())[0]
return (
f'"{template_part_key}": {{"description": "{description_value}"}}'
)
return ""

def _copy_until_and_remove_section(self, pos):
"""
Copy characters to the transcriber until the given position,
Expand Down

0 comments on commit 92b749d

Please sign in to comment.