1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-15 14:24:55 +00:00
CC-Tweaked/tools/language.py
SquidDev a35dcb28ef Import translations and clean up
- Strip any gui._.config options. These haven't been used since 1.12
   and while they may return, it doesn't seem worth it right now.
 - Fix a couple of typos in the English translations.
 - Import from https://i18n.tweaked.cc. There's definitely some problems
   with the import - empty translations are still included, so we write
   a script to strip them.
2020-06-18 13:10:51 +01:00

43 lines
1.2 KiB
Python

"""
Rewrites language files in order to be consistent with en_us.
This will take every given language file and rewrite it to be in the same
order as the en_us file. Any keys which appear in the given file, but not
in en_us are removed.
Note, this is not intended to be a fool-proof tool, rather a quick way to
ensure language files are mostly correct.
"""
import pathlib, sys, json
from collections import OrderedDict
root = pathlib.Path("src/main/resources/assets/computercraft/lang")
with (root / "en_us.json").open(encoding="utf-8") as file:
en_us = json.load(file, object_hook=OrderedDict)
for path in root.glob("*.json"):
if path.name == "en_us.json":
continue
with path.open(encoding="utf-8") as file:
lang = json.load(file)
out = OrderedDict()
missing = 0
for k in en_us.keys():
if k not in lang:
missing += 1
elif lang[k] == "":
print("{} has empty translation for {}".format(path.name, k))
else:
out[k] = lang[k]
with path.open("w", encoding="utf-8", newline="\n") as file:
json.dump(out, file, indent=4, ensure_ascii=False)
file.write("\n")
if missing > 0:
print("{} has {} missing translations.".format(path.name, missing))