Last active
May 31, 2020 15:19
-
-
Save Quintenps/7f3665a3b9392d0e0a87ccd4e06fce7b to your computer and use it in GitHub Desktop.
ow translator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
from googletrans import Translator | |
translator = Translator() | |
GAMEMODES = "arcade-modes.json" | |
MAPS = "maps.json" | |
HEROES = "heroes.json" | |
OW_LABELS = ["Permanent", "Daily", "Weekly"] | |
GOOGLE_LANGUAGE_KEYS = { | |
"BR": "pt", | |
"CN": "zh-CN", | |
"DE": "de", | |
"ES": "es", | |
"US": "en", | |
"FR": "fr", | |
"IT": "it", | |
"JP": "ja", | |
"KR": "ko", | |
"MX": "es", | |
"PL": "pl", | |
"RU": "ru", | |
"TW": "zh-TW", | |
} | |
# English builder | |
# Gamemodes | |
with open("extract/Overwatch-enUS/" + GAMEMODES, encoding="utf8") as f: | |
data = json.loads(f.read()) | |
us_overwatch_modes = [] | |
for mode in data: | |
if mode['About'] is not None: | |
us_overwatch_modes.append({"Name": mode['Name'].replace(' <tx0C0000000001FEE9>','').replace("'", '`'), "Players": mode['About'][0] }) | |
# Maps | |
with open("extract/Overwatch-enUS/" + MAPS, encoding="utf8") as f: | |
data = json.loads(f.read()) | |
us_overwatch_maps = [] | |
for map in data: | |
us_overwatch_maps.append(data[map]['Name']) | |
# Heroes | |
with open("extract/Overwatch-enUS/" + HEROES, encoding="utf8") as f: | |
data = json.loads(f.read()) | |
us_overwatch_heroes = [] | |
for hero in data: | |
us_overwatch_heroes.append(data[hero]['Name']) | |
for translationDirectory in os.listdir("extract/"): | |
json_output = {} | |
print(translationDirectory) | |
#Gamemodes | |
loopCount = 0 | |
with open("extract/" + translationDirectory + "/" + GAMEMODES, encoding="utf8") as f: | |
data = json.loads(f.read()) | |
overwatch_modes = {} | |
for mode in data: | |
if mode['About'] is not None: | |
overwatch_modes[us_overwatch_modes[loopCount]['Name']+us_overwatch_modes[loopCount]['Players']] = {"Name": mode['Name'].replace(' <tx0C0000000001FEE9>','').replace("'", '`'), "Players": mode['About'][0]} | |
loopCount+=1 | |
print(overwatch_modes) | |
# Maps | |
loopCount = 0 | |
with open("extract/" + translationDirectory + "/" + MAPS, encoding="utf8") as f: | |
data = json.loads(f.read()) | |
overwatch_maps = {} | |
for maps in data: | |
overwatch_maps[us_overwatch_maps[loopCount]] = data[maps]['Name'] | |
loopCount += 1 | |
del overwatch_maps[None] | |
# Heroes | |
loopCount = 0 | |
with open("extract/" + translationDirectory + "/" + HEROES, encoding="utf8") as f: | |
data = json.loads(f.read()) | |
overwatch_heroes = {} | |
for hero in data: | |
overwatch_heroes[us_overwatch_heroes[loopCount]] = data[hero]['Name'] | |
loopCount += 1 | |
del overwatch_heroes[None] | |
output = { | |
"general": { | |
"contributors": "contributors", | |
"notifications": "notifications", | |
"settings": "settings", | |
}, | |
"message": { | |
"warning": str.capitalize(translator.translate("Warning", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text) | |
}, | |
"profile": { | |
"contributor_subline": str.capitalize(translator.translate("Contributor since --- with a total of --- contributions", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text).replace("---", "{date}", 1).replace("---", "{amount}", 1), | |
"about": "About", | |
"last_submit": "Last submit", | |
"favourite_arcade_modes": str.capitalize(translator.translate("Favourite arcade modes", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"favourite_arcade_heroes": str.capitalize(translator.translate("Favourite heroes", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"favourite_arcade_maps": str.capitalize(translator.translate("Favourite maps", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text) | |
}, | |
"overwatch": { | |
"labels": { | |
"Permanent": str.capitalize(translator.translate("Permanent", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"Daily": str.capitalize(translator.translate("Daily", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"Weekly": str.capitalize(translator.translate("Weekly", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
}, | |
"day_resets_in": str.capitalize(translator.translate("Day resets at", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"not_updated_yet": str.capitalize(translator.translate("Today's arcade has not been updated yet", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"maps": overwatch_maps, | |
"heroes": overwatch_heroes, | |
"arcademodes": overwatch_modes | |
}, | |
"footer": { | |
"copyright_materials": str.capitalize(translator.translate("Game content and materials are trademarks and copyrights of their respective publisher and its licensors. All rights reserved.", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"copyright_site": str.capitalize(translator.translate("This site is licensed under a", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"made_by": str.capitalize(translator.translate("This site is made for fun by", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
"contributors": str.capitalize(translator.translate("and maintained by the", dest=GOOGLE_LANGUAGE_KEYS[translationDirectory[-2:]]).text), | |
} | |
} | |
with open('output/' + str.lower(translationDirectory[-2:]) + ".json", 'w', encoding="utf8") as outfile: | |
json.dump(output, outfile, indent=4, sort_keys=True, ensure_ascii=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment