Skip to content

Commit 61f6e2f

Browse files
committed
✨ Add enum information to string catalog json output
1 parent fbe7b99 commit 61f6e2f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/gen_str_catalog.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,17 @@ def fq_name(node):
195195
return enums
196196

197197

198-
def write_json(messages, modules, extra_inputs: list[str], filename: str, stable_ids):
198+
def write_json(messages, modules, enums, extra_inputs: list[str], filename: str, stable_ids):
199199
str_catalog = dict(messages=list(messages.values()), modules=list(modules.values()))
200200
for msg in stable_ids.get("messages"):
201201
if not msg in str_catalog["messages"]:
202202
str_catalog["messages"].append(msg)
203203
for mod in stable_ids.get("modules"):
204204
if not mod in str_catalog["modules"]:
205205
str_catalog["modules"].append(mod)
206+
str_catalog["enums"] = {}
207+
for (k, (_, v)) in enums.items():
208+
str_catalog["enums"].update({k: {value: name for (name, value) in v.items()}})
206209
for extra in extra_inputs:
207210
with open(extra, "r") as f:
208211
str_catalog.update(json.load(f))
@@ -427,11 +430,8 @@ def main():
427430

428431
check_module_limit(modules, args.module_id_max)
429432

430-
if args.json_output is not None:
431-
write_json(messages, modules, args.json_input, args.json_output, stable_output)
432-
433-
if args.xml_output is not None:
434-
enums = {}
433+
enums = {}
434+
if args.xml_output is not None or args.json_output is not None:
435435
if args.cpp_output is not None:
436436
try:
437437
enums = {
@@ -452,6 +452,10 @@ def main():
452452
else:
453453
print("XML output without C++ output: enum lookup will not be available")
454454

455+
if args.json_output is not None:
456+
write_json(messages, modules, enums, args.json_input, args.json_output, stable_output)
457+
458+
if args.xml_output is not None:
455459
write_xml(
456460
messages,
457461
modules,

0 commit comments

Comments
 (0)