Page MenuHomePhabricator
Paste P63840

Phabricator translation rescue script
ActivePublic

Authored by Pppery on Jun 1 2024, 10:29 PM.
Tags
None
Referenced Files
F54850148: Phabricator translation rescue script
Jun 1 2024, 10:29 PM
Subscribers
None
def run():
translations = {}
# The "oldtranslations" dir points to a checkout of rPHTR25fd1d3ee0158680a93ebad8eac5363348a980f8
os.chdir("../../oldtranslations/projects/libphutil/core")
for file in os.listdir():
if file not in ("en.json","qqq.json","raw.json"):
translations[file.replace(".json","")] = json.load(open(file,encoding="utf8"))
# The "/translations" dir points to a checkout of the latest commit of rPHTR
os.chdir("../../../../translations/projects")
for key in translations:
ltr = translations[key]
rescued = 0
for root, dirs, files in os.walk("."):
touched = False
if "en.json" not in files:
continue
source = json.load(open(root+"/en.json",encoding="utf8"))
if (key + ".json") in files:
ntr = json.load(open(root+"/"+key+".json",encoding="utf8"))
else:
ntr = {}
for key2 in ltr.copy():
if key2 in source:
if key2 not in ntr:
rescued += 1
ntr[key2] = ltr[key2]
touched = True
del ltr[key2]
if touched:
fp = open(root+"/"+key+".json","w",encoding="utf8")
json.dump(ntr, fp, ensure_ascii=False, indent="\t")
print(rescued,"translations into " + key + " rescued")
print(len(ltr),"translations into " + key + " could not be found")