1919STATS_URL = "https://hosted.weblate.org/api/components/catima/catima/statistics/"
2020
2121
22- class Error (Exception ):
23- pass
24-
25-
2622def get_weblate_langs () -> List [Tuple [str , int ]]:
27- url = STATS_URL
23+ r = requests .get (STATS_URL , timeout = 5 )
24+ r .raise_for_status ()
2825 results = []
29- for _ in range (16 ): # avoid endless loops just in case
30- r = requests .get (url , timeout = 5 )
31- r .raise_for_status ()
32- data = r .json ()
33- for lang in data ["results" ]:
34- if lang ["code" ] != "en" :
35- code = REPLACE_CODES .get (lang ["code" ], lang ["code" ]).replace ("_" , "-r" )
36- results .append ((code , round (lang ["translated_percent" ])))
37- url = data ["next" ]
38- if not url :
39- return sorted (results )
40- if not url .split ("?" )[0 ] == STATS_URL :
41- raise Error (f"Unexpected next URL: { url } " )
42- raise Error ("Too many pages" )
26+ for lang in r .json ()["results" ]:
27+ if lang ["code" ] != "en" :
28+ code = REPLACE_CODES .get (lang ["code" ], lang ["code" ]).replace ("_" , "-r" )
29+ results .append ((code , round (lang ["translated_percent" ])))
30+ return sorted (results )
4331
4432
4533def get_dir_langs () -> List [str ]:
@@ -54,7 +42,7 @@ def get_dir_langs() -> List[str]:
5442def get_xml_langs () -> List [Tuple [str , bool ]]:
5543 results = []
5644 in_section = False
57- with open ("app/src/main/res/values/settings.xml" , encoding = "utf-8" ) as fh :
45+ with open ("app/src/main/res/values/settings.xml" ) as fh :
5846 for line in fh :
5947 if not in_section and 'name="locale_values"' in line :
6048 in_section = True
@@ -71,7 +59,7 @@ def get_xml_langs() -> List[Tuple[str, bool]]:
7159def update_xml_langs (langs : List [Tuple [str , bool ]]) -> None :
7260 lines : List [str ] = []
7361 in_section = False
74- with open ("app/src/main/res/values/settings.xml" , encoding = "utf-8" ) as fh :
62+ with open ("app/src/main/res/values/settings.xml" ) as fh :
7563 for line in fh :
7664 if not in_section and 'name="locale_values"' in line :
7765 in_section = True
@@ -82,7 +70,7 @@ def update_xml_langs(langs: List[Tuple[str, bool]]) -> None:
8270 else :
8371 continue
8472 lines .append (line )
85- with open ("app/src/main/res/values/settings.xml" , "w" , encoding = "utf-8" ) as fh :
73+ with open ("app/src/main/res/values/settings.xml" , "w" ) as fh :
8674 for line in lines :
8775 fh .write (line )
8876
0 commit comments