mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-08-01 17:38:40 +00:00
Restyled by yapf
This commit is contained in:
25
translate.py
25
translate.py
@ -91,7 +91,8 @@ with open("./resources/strings/strings.xml", "r") as f:
|
||||
os.makedirs(f"./resources-{l[0]}/strings/", exist_ok=True)
|
||||
try:
|
||||
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:
|
||||
curr = BeautifulSoup("", features=["xml"])
|
||||
print(f"{i} of {langLength}: Translating English to {l[2]}")
|
||||
@ -99,13 +100,9 @@ with open("./resources/strings/strings.xml", "r") as f:
|
||||
soup.find(name="strings").insert_before("\n\n")
|
||||
soup.find(name="strings").insert_before(
|
||||
Comment(
|
||||
f"\n Generated by Google Translate: English to {l[2]}\n "
|
||||
+ GoogleTranslator(source="en", target=l[1]).translate(
|
||||
"Generated by Google Translate from English"
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
)
|
||||
f"\n Generated by Google Translate: English to {l[2]}\n " +
|
||||
GoogleTranslator(source="en", target=l[1]).translate(
|
||||
"Generated by Google Translate from English") + "\n"))
|
||||
soup.find(name="strings").insert_before("\n\n")
|
||||
|
||||
for s in soup.find(name="strings").findAll(name="string"):
|
||||
@ -117,20 +114,20 @@ with open("./resources/strings/strings.xml", "r") as f:
|
||||
if s_curr:
|
||||
s.string = s_curr.string
|
||||
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:
|
||||
s.string = a.title()
|
||||
else:
|
||||
s.string = a
|
||||
for s in soup.find(name="strings").findAll(
|
||||
string=lambda text: isinstance(text, Comment)
|
||||
):
|
||||
string=lambda text: isinstance(text, Comment)):
|
||||
s.insert_before(" ")
|
||||
s.replace_with(
|
||||
Comment(
|
||||
" " + GoogleTranslator(source="en", target=l[1]).translate(s) + " "
|
||||
)
|
||||
)
|
||||
" " +
|
||||
GoogleTranslator(source="en", target=l[1]).translate(s) +
|
||||
" "))
|
||||
|
||||
# print(str(soup))
|
||||
with open(f"./resources-{l[0]}/strings/strings.xml", "wb") as w:
|
||||
|
Reference in New Issue
Block a user