mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-08-07 12:28:39 +00:00
Restyled by autopep8
This commit is contained in:
12
translate.py
12
translate.py
@ -90,7 +90,8 @@ with open("./resources/strings/strings.xml", "r") as f:
|
|||||||
os.makedirs(f"./resources-{l[0]}/strings/", exist_ok=True)
|
os.makedirs(f"./resources-{l[0]}/strings/", exist_ok=True)
|
||||||
try:
|
try:
|
||||||
with open(f"./resources-{l[0]}/strings/corrections.xml", "r") as r:
|
with open(f"./resources-{l[0]}/strings/corrections.xml", "r") as r:
|
||||||
curr = BeautifulSoup(r.read().replace('\r', ''), features="xml")
|
curr = BeautifulSoup(
|
||||||
|
r.read().replace('\r', ''), features="xml")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
curr = BeautifulSoup("", features=["xml"])
|
curr = BeautifulSoup("", features=["xml"])
|
||||||
print(f"{i} of {langLength}: Translating English to {l[2]}")
|
print(f"{i} of {langLength}: Translating English to {l[2]}")
|
||||||
@ -105,20 +106,23 @@ with open("./resources/strings/strings.xml", "r") as f:
|
|||||||
|
|
||||||
for s in soup.find(name="strings").findAll(name="string"):
|
for s in soup.find(name="strings").findAll(name="string"):
|
||||||
s.insert_before(" ")
|
s.insert_before(" ")
|
||||||
if s["id"] in exceptionIds: continue
|
if s["id"] in exceptionIds:
|
||||||
|
continue
|
||||||
|
|
||||||
s_curr = curr.find(name="string", attrs={"id": s["id"]})
|
s_curr = curr.find(name="string", attrs={"id": s["id"]})
|
||||||
if s_curr:
|
if s_curr:
|
||||||
s.string = s_curr.string
|
s.string = s_curr.string
|
||||||
else:
|
else:
|
||||||
a = GoogleTranslator(source='en', target=l[1]).translate(s.string)
|
a = GoogleTranslator(
|
||||||
|
source='en', target=l[1]).translate(s.string)
|
||||||
if s["id"] in titleIds:
|
if s["id"] in titleIds:
|
||||||
s.string = a.title()
|
s.string = a.title()
|
||||||
else:
|
else:
|
||||||
s.string = a
|
s.string = a
|
||||||
for s in soup.find(name="strings").findAll(string=lambda text: isinstance(text, Comment)):
|
for s in soup.find(name="strings").findAll(string=lambda text: isinstance(text, Comment)):
|
||||||
s.insert_before(" ")
|
s.insert_before(" ")
|
||||||
s.replace_with(Comment(" " + GoogleTranslator(source='en', target=l[1]).translate(s) + " "))
|
s.replace_with(
|
||||||
|
Comment(" " + GoogleTranslator(source='en', target=l[1]).translate(s) + " "))
|
||||||
|
|
||||||
# print(str(soup))
|
# print(str(soup))
|
||||||
with open(f"./resources-{l[0]}/strings/strings.xml", "wb") as w:
|
with open(f"./resources-{l[0]}/strings/strings.xml", "wb") as w:
|
||||||
|
Reference in New Issue
Block a user