Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raspi committed Mar 15, 2023
1 parent a54b1a9 commit 95b5c4d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions json_merge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/env python3

# Merge localization JSON files generated with gotext with possible new strings

from json import load, dump
from pathlib import Path
from shutil import move
Expand All @@ -11,7 +13,8 @@
if len(argv) != 3:
print("too few args", file=stderr)
print("", file=stderr)
print(f"{argv[0]} <> <>", file=stderr)
print(f"{argv[0]} <target file> <source file>", file=stderr)
print(f"{argv[0]} messages.json out.json", file=stderr)
exit(1)

messages_file = Path(argv[1])
Expand Down Expand Up @@ -40,9 +43,11 @@
print(f" Adding: '{x['id']}'")
merged['messages'].append(x)

# Write to temporary file
tmpf = NamedTemporaryFile("w", prefix="merged", suffix=".json", encoding="utf-8", delete=False)
with tmpf as f:
dump(merged, f, indent=' ' * 8, ensure_ascii=False)

newpath = move(tmpf.name, messages_file)
print(tmpf.name, "->", newpath)
# Move temp file
newpath = move(tmpf.name, messages_file)
print(tmpf.name, "->", newpath)

0 comments on commit 95b5c4d

Please sign in to comment.