Skip to content

Commit

Permalink
update translation automations
Browse files Browse the repository at this point in the history
handle more corner cases, missing subdirectories, deduplicate files
  • Loading branch information
JarbasAl committed May 17, 2024
1 parent 349f71b commit 3169d05
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions scripts/sync_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
data = json.load(f)
for fid, samples in data.items():
if samples:
os.makedirs(f"{locale}/{lang.lower()}", exist_ok=True)
samples = [s.strip() for s in samples
if s and s.strip() != "[UNUSED]"] # s may be None
samples = list(set([s.strip() for s in samples
if s and s.strip() != "[UNUSED]"])) # s may be None
if fid.startswith("/"):
p = f"{locale}/{lang.lower()}{fid}"
else:
p = f"{locale}/{lang.lower()}/{fid}"
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

Expand All @@ -32,9 +36,13 @@
data = json.load(f)
for fid, samples in data.items():
if samples:
os.makedirs(f"{locale}/{lang.lower()}", exist_ok=True)
samples = [s.strip() for s in samples
if s and s.strip() != "[UNUSED]"] # s may be None
samples = list(set([s.strip() for s in samples
if s and s.strip() != "[UNUSED]"])) # s may be None
if fid.startswith("/"):
p = f"{locale}/{lang.lower()}{fid}"
else:
p = f"{locale}/{lang.lower()}/{fid}"
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

Expand All @@ -43,9 +51,13 @@
data = json.load(f)
for fid, samples in data.items():
if samples:
os.makedirs(f"{locale}/{lang.lower()}", exist_ok=True)
samples = [s.strip() for s in samples
if s and s.strip() != "[UNUSED]"] # s may be None
samples = list(set([s.strip() for s in samples
if s and s.strip() != "[UNUSED]"])) # s may be None
if fid.startswith("/"):
p = f"{locale}/{lang.lower()}{fid}"
else:
p = f"{locale}/{lang.lower()}/{fid}"
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

Expand All @@ -54,9 +66,13 @@
data = json.load(f)
for fid, samples in data.items():
if samples:
os.makedirs(f"{locale}/{lang.lower()}", exist_ok=True)
samples = [s.strip() for s in samples
if s and s.strip() != "[UNUSED]"] # s may be None
samples = list(set([s.strip() for s in samples
if s and s.strip() != "[UNUSED]"])) # s may be None
if fid.startswith("/"):
p = f"{locale}/{lang.lower()}{fid}"
else:
p = f"{locale}/{lang.lower()}/{fid}"
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

0 comments on commit 3169d05

Please sign in to comment.