Skip to content

Commit

Permalink
Script for adding other languages to existing output files.
Browse files Browse the repository at this point in the history
This can be used to update an existing set of output files with new translations for the additional languages like Korean and Chinese, without having to rerun the main scraper script.
  • Loading branch information
doxxx committed Feb 15, 2019
1 parent ef7fc5f commit 45e901c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions add_other_lang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json
import sys


CLASSES = [
"Carpenter",
"Blacksmith",
"Armorer",
"Goldsmith",
"Leatherworker",
"Weaver",
"Alchemist",
"Culinarian",
]


def main():
additional_languages = {}
for arg in sys.argv[1:]:
lang, path = arg.split("=", 2)
with open(path, mode="rt", encoding="utf-8") as fp:
print(f"Loading additional language '{lang}' from: {path}")
additional_languages[lang] = json.load(fp)
for cls in CLASSES:
with open(f"out/{cls}.json", mode="rt", encoding="utf-8") as fp:
recipes = json.load(fp)
for recipe in recipes:
for lang in additional_languages.keys():
names = additional_languages[lang]
english_name = recipe['name']['en']
recipe['name'][lang] = names.get(english_name) or english_name
with open(f"out/{cls}.json", mode="wt", encoding="utf-8") as db_file:
json.dump(recipes, db_file, indent=2, sort_keys=True, ensure_ascii=False)


if __name__ == '__main__':
main()

0 comments on commit 45e901c

Please sign in to comment.