From 5848cd4e1782bbbf25f87c477be789991e54b10d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Jan 2024 18:16:15 +0000 Subject: [PATCH 1/5] Restyled by autopep8 --- translate.py | 150 ++++++++++++++++++++++++++------------------------- 1 file changed, 77 insertions(+), 73 deletions(-) diff --git a/translate.py b/translate.py index 7052db5..9a5323f 100644 --- a/translate.py +++ b/translate.py @@ -40,42 +40,42 @@ import os # * Google Translate language mnemonic, # * Language familiar name (mainly for reference) languages: list[tuple[str, str, str]] = [ - ("ara", "ar", "Arabic"), - ("bul", "bg", "Bulgarian"), - ("zhs", "zh-CN", "Chinese (Simplified)"), - ("zht", "zh-TW", "Chinese (Traditional)"), - ("hrv", "hr", "Croatian"), - ("ces", "cs", "Czech"), - ("dan", "da", "Danish"), - ("dut", "nl", "Dutch"), - ("deu", "de", "German"), - ("gre", "el", "Greek"), - # ("eng", "en", "English"), - ("est", "et", "Estonian"), - ("fin", "fi", "Finnish"), - ("fre", "fr", "French"), - ("heb", "iw", "Hebrew"), - ("hun", "hu", "Hungarian"), - ("ind", "id", "Indonesian"), - ("ita", "it", "Italian"), - ("jpn", "ja", "Japanese"), - ("kor", "ko", "Korean"), - ("lav", "lv", "Latvian"), - ("lit", "lt", "Lithuanian"), - ("zsm", "ms", "Standard (Bahasa) Malay"), - ("nob", "no", "Norwegian"), - ("pol", "pl", "Polish"), - ("por", "pt", "Portuguese"), - ("ron", "ro", "Romanian"), - # ("rus", "ru", "Russian"), - ("slo", "sk", "Slovak"), - ("slv", "sl", "Slovenian"), - ("spa", "es", "Spanish"), - ("swe", "sv", "Swedish"), - ("tha", "th", "Thai"), - ("tur", "tr", "Turkish"), - ("ukr", "uk", "Ukrainian"), - ("vie", "vi", "Vietnamese") + ("ara", "ar", "Arabic"), + ("bul", "bg", "Bulgarian"), + ("zhs", "zh-CN", "Chinese (Simplified)"), + ("zht", "zh-TW", "Chinese (Traditional)"), + ("hrv", "hr", "Croatian"), + ("ces", "cs", "Czech"), + ("dan", "da", "Danish"), + ("dut", "nl", "Dutch"), + ("deu", "de", "German"), + ("gre", "el", "Greek"), + # ("eng", "en", "English"), + ("est", "et", "Estonian"), + ("fin", "fi", "Finnish"), + ("fre", "fr", "French"), + ("heb", "iw", "Hebrew"), + ("hun", "hu", "Hungarian"), + ("ind", "id", "Indonesian"), + ("ita", "it", "Italian"), + ("jpn", "ja", "Japanese"), + ("kor", "ko", "Korean"), + ("lav", "lv", "Latvian"), + ("lit", "lt", "Lithuanian"), + ("zsm", "ms", "Standard (Bahasa) Malay"), + ("nob", "no", "Norwegian"), + ("pol", "pl", "Polish"), + ("por", "pt", "Portuguese"), + ("ron", "ro", "Romanian"), + # ("rus", "ru", "Russian"), + ("slo", "sk", "Slovak"), + ("slv", "sl", "Slovenian"), + ("spa", "es", "Spanish"), + ("swe", "sv", "Swedish"), + ("tha", "th", "Thai"), + ("tur", "tr", "Turkish"), + ("ukr", "uk", "Ukrainian"), + ("vie", "vi", "Vietnamese") ] langLength = len(languages) @@ -85,42 +85,46 @@ titleIds: list[str] = [] i = 1 with open("./resources/strings/strings.xml", "r") as f: - c = f.read().replace('\r', '') - for l in languages: - 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") - except FileNotFoundError: - curr = BeautifulSoup("", features=["xml"]) - print(f"{i} of {langLength}: Translating English to {l[2]}") - soup = BeautifulSoup(c, features="xml") - 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") - ) - soup.find(name="strings").insert_before("\n\n") + c = f.read().replace('\r', '') + for l in languages: + 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") + except FileNotFoundError: + curr = BeautifulSoup("", features=["xml"]) + print(f"{i} of {langLength}: Translating English to {l[2]}") + soup = BeautifulSoup(c, features="xml") + 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") + ) + soup.find(name="strings").insert_before("\n\n") - for s in soup.find(name="strings").findAll(name="string"): - s.insert_before(" ") - if s["id"] in exceptionIds: continue - - s_curr = curr.find(name="string", attrs={ "id": s["id"] }) - if s_curr: - s.string = s_curr.string - else: - 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)): - s.insert_before(" ") - s.replace_with(Comment(" " + GoogleTranslator(source='en', target=l[1]).translate(s) + " ")) + for s in soup.find(name="strings").findAll(name="string"): + s.insert_before(" ") + if s["id"] in exceptionIds: + continue - #print(str(soup)) - with open(f"./resources-{l[0]}/strings/strings.xml", "wb") as w: - w.write(soup.encode("utf-8") + b"\n") - i += 1 + s_curr = curr.find(name="string", attrs={"id": s["id"]}) + if s_curr: + s.string = s_curr.string + else: + 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)): + s.insert_before(" ") + s.replace_with( + Comment(" " + GoogleTranslator(source='en', target=l[1]).translate(s) + " ")) + + # print(str(soup)) + with open(f"./resources-{l[0]}/strings/strings.xml", "wb") as w: + w.write(soup.encode("utf-8") + b"\n") + i += 1 From 82d69483d6f7c25cb3eadceba9a70500d4eeac89 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Jan 2024 18:16:17 +0000 Subject: [PATCH 2/5] Restyled by black --- translate.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/translate.py b/translate.py index 9a5323f..9f89bc8 100644 --- a/translate.py +++ b/translate.py @@ -75,7 +75,7 @@ languages: list[tuple[str, str, str]] = [ ("tha", "th", "Thai"), ("tur", "tr", "Turkish"), ("ukr", "uk", "Ukrainian"), - ("vie", "vi", "Vietnamese") + ("vie", "vi", "Vietnamese"), ] langLength = len(languages) @@ -85,22 +85,25 @@ titleIds: list[str] = [] i = 1 with open("./resources/strings/strings.xml", "r") as f: - c = f.read().replace('\r', '') + c = f.read().replace("\r", "") for l in languages: 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]}") soup = BeautifulSoup(c, features="xml") 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") + 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" + ) ) soup.find(name="strings").insert_before("\n\n") @@ -113,16 +116,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)): + for s in soup.find(name="strings").findAll( + string=lambda text: isinstance(text, Comment) + ): s.insert_before(" ") s.replace_with( - Comment(" " + GoogleTranslator(source='en', target=l[1]).translate(s) + " ")) + Comment( + " " + GoogleTranslator(source="en", target=l[1]).translate(s) + " " + ) + ) # print(str(soup)) with open(f"./resources-{l[0]}/strings/strings.xml", "wb") as w: From 59e3ae144180c9dec9d62e9bb27a9dc65c09f3ce Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Jan 2024 18:16:19 +0000 Subject: [PATCH 3/5] Restyled by isort --- translate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/translate.py b/translate.py index 9f89bc8..f43e9a3 100644 --- a/translate.py +++ b/translate.py @@ -31,10 +31,11 @@ # #################################################################################### -from deep_translator import GoogleTranslator -from bs4 import BeautifulSoup, Comment import os +from bs4 import BeautifulSoup, Comment +from deep_translator import GoogleTranslator + # List of tuples in the form os: # * Garmin IQ language three letter mnemonic, # * Google Translate language mnemonic, From 58b5c7d0c4abdb5a70a90a3a2cd66a5b71c3bc16 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Jan 2024 18:16:22 +0000 Subject: [PATCH 4/5] Restyled by reorder-python-imports --- translate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/translate.py b/translate.py index f43e9a3..ec00292 100644 --- a/translate.py +++ b/translate.py @@ -30,10 +30,10 @@ # * https://www.crummy.com/software/BeautifulSoup/bs4/doc/#xml # #################################################################################### - import os -from bs4 import BeautifulSoup, Comment +from bs4 import BeautifulSoup +from bs4 import Comment from deep_translator import GoogleTranslator # List of tuples in the form os: From 65c275ae190b52192851f7bcc5be8999db535ed8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Jan 2024 18:16:26 +0000 Subject: [PATCH 5/5] Restyled by yapf --- translate.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/translate.py b/translate.py index ec00292..74c22a8 100644 --- a/translate.py +++ b/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: