Skip to content

Commit

Permalink
update translation automations
Browse files Browse the repository at this point in the history
handle more corner cases, such as upper case lang codes and missing directories
  • Loading branch information
JarbasAl committed May 16, 2024
1 parent b69f21a commit a86fe4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions scripts/prepare_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
elif fid.endswith(".rx"):
regexes[fid] = strings

os.makedirs(f"{tx}/{lang}", exist_ok=True)
os.makedirs(f"{tx}/{lang.lower()}", exist_ok=True)
if intents:
with open(f"{tx}/{lang}/intents.json", "w") as f:
with open(f"{tx}/{lang.lower()}/intents.json", "w") as f:
json.dump(intents, f, indent=4)
if dialogs:
with open(f"{tx}/{lang}/dialogs.json", "w") as f:
with open(f"{tx}/{lang.lower()}/dialogs.json", "w") as f:
json.dump(dialogs, f, indent=4)
if vocs:
with open(f"{tx}/{lang}/vocabs.json", "w") as f:
with open(f"{tx}/{lang.lower()}/vocabs.json", "w") as f:
json.dump(vocs, f, indent=4)
if regexes:
with open(f"{tx}/{lang}/regexes.json", "w") as f:
with open(f"{tx}/{lang.lower()}/regexes.json", "w") as f:
json.dump(regexes, f, indent=4)
16 changes: 12 additions & 4 deletions scripts/sync_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,47 @@
with open(intents) as f:
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
with open(f"{locale}/{lang}/{fid}", "w") as f:
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

if os.path.isfile(dialogs):
with open(dialogs) as f:
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
with open(f"{locale}/{lang}/{fid}", "w") as f:
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

if os.path.isfile(vocs):
with open(vocs) as f:
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
with open(f"{locale}/{lang}/{fid}", "w") as f:
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

if os.path.isfile(regexes):
with open(regexes) as f:
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
with open(f"{locale}/{lang}/{fid}", "w") as f:
with open(f"{locale}/{lang.lower()}/{fid}", "w") as f:
f.write("\n".join(sorted(samples)))

0 comments on commit a86fe4b

Please sign in to comment.