Skip to content

Instantly share code, notes, and snippets.

@New-dev0
Last active August 21, 2022 04:21
Show Gist options
  • Save New-dev0/c7d0d1eb514d311e8e3b687ae5cbe5f3 to your computer and use it in GitHub Desktop.
Save New-dev0/c7d0d1eb514d311e8e3b687ae5cbe5f3 to your computer and use it in GitHub Desktop.
from pyUltroid.fns.tools import translate
from threading import Thread
from yaml import safe_load
from glob import glob
All = glob("strings/strings/*.yml")
en = "strings/strings/en.yml"
strings = safe_load(open(en, "r"))
All.remove(en)
Threads = []
def func(rema, name, lang):
newc = ""
for key in rema:
try:
res = translate(strings[key], lang_tgt=name).replace("\n", "\\n").replace('"', "'")
newc += f'\n{key}: "{res}"'
except Exception as er:
print(name, er)
continue
if newc:
with open(lang, "a") as file:
file.write(newc)
for lang in All:
name = lang.split("/")[-1].split(".")[0]
try:
cont = safe_load(open(lang, "r"))
except Exception as er:
print(lang, er)
continue
exclu = list(cont.keys() - strings.keys())
for _ in exclu:
del cont[_]
rema = list(strings.keys() - cont.keys())
if rema:
thre = Thread(target=lambda: func(rema, name, lang))
thre.start()
Threads.append(thre)
for thr in Threads:
thr.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment