2021-04-28 20:28:52 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-03-15 21:52:13 +00:00
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2020 The CC: Tweaked Developers
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-06-18 12:10:51 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2022-11-10 09:12:28 +00:00
|
|
|
import json
|
|
|
|
import pathlib
|
2020-06-18 12:10:51 +00:00
|
|
|
from collections import OrderedDict
|
|
|
|
|
2022-11-10 09:12:28 +00:00
|
|
|
root = pathlib.Path("projects/common/src/main/resources/assets/computercraft/lang")
|
2020-06-18 12:10:51 +00:00
|
|
|
|
2022-11-20 13:00:43 +00:00
|
|
|
with open("projects/fabric/src/generated/resources/assets/computercraft/lang/en_us.json", encoding="utf-8") as file:
|
2020-06-18 12:10:51 +00:00
|
|
|
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))
|