From f471346f044930ed0f04b9d01e1779884c919d9b Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 10 May 2021 18:05:41 -0700 Subject: Write script that uses the weblate API to help determine which languages are ready for a release --- docs/check-weblate.py | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100755 docs/check-weblate.py (limited to 'docs/check-weblate.py') diff --git a/docs/check-weblate.py b/docs/check-weblate.py new file mode 100755 index 00000000..8283deea --- /dev/null +++ b/docs/check-weblate.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 +import sys +import httpx +import asyncio +import time + + +api_token = None +languages = {} +app_translations = {} +docs_translations = {} + + +async def api(path): + url = f"https://hosted.weblate.org{path}" + + async with httpx.AsyncClient() as client: + r = await client.get(url, headers={"Authorization": f"Token {api_token}"}) + + if r.status_code == 200: + print(f"GET {url}") + return r.json() + else: + print(f"GET {url} | error {r.status_code}") + return None + + +async def get_app_translation(lang_code): + global app_translations + obj = await api(f"/api/translations/onionshare/translations/{lang_code}/") + if obj: + app_translations[lang_code] = obj["translated_percent"] + + +async def get_docs_translation(component, lang_code): + global docs_translations + obj = await api(f"/api/translations/onionshare/{component}/{lang_code}/") + if obj: + if component not in docs_translations: + docs_translations[component] = {} + docs_translations[component][lang_code] = obj["translated_percent"] + + +async def app_percent_output(percent_min, percent_max=100): + out = [] + for lang_code in languages: + if ( + app_translations[lang_code] >= percent_min + and app_translations[lang_code] <= percent_max + ): + out.append( + f"{languages[lang_code]} ({lang_code}), {app_translations[lang_code]}%" + ) + + out.sort() + + print(f"App translations >= {percent_min}%") + print("=======================") + print("\n".join(out)) + + print("") + + +async def docs_percent_output(percent_min, percent_max=100): + out = [] + for lang_code in languages: + include_language = True + percentages = [] + + for component in docs_translations: + if lang_code not in docs_translations[component]: + include_language = False + break + + percentages.append(docs_translations[component][lang_code]) + + if ( + docs_translations[component][lang_code] < percent_min + or docs_translations[component][lang_code] > percent_max + ): + include_language = False + break + + if include_language: + percentages = [f"{p}%" for p in percentages] + percentages = ", ".join(percentages) + out.append(f"{languages[lang_code]} ({lang_code}), {percentages}") + + out.sort() + + print(f"Docs translations >= {percent_min}%") + print("========================") + print("\n".join(out)) + + print("") + + +async def main(): + global api_token, languages, app_translations, docs_translations + + if len(sys.argv) != 2: + print(f"Usage: {sys.argv[0]} API_KEY") + print( + "You can find your personal API key at: https://hosted.weblate.org/accounts/profile/#api" + ) + return + + api_token = sys.argv[1] + + # Get the list of languages in the OnionShare project + res = await api("/api/projects/onionshare/languages/") + for obj in res: + languages[obj["code"]] = obj["language"] + + # Get the app translations for each language + await asyncio.gather(*[get_app_translation(lang_code) for lang_code in languages]) + + # Get the documentation translations for each component for each language + for component in [ + "doc-advanced", + "doc-develop", + "doc-features", + "doc-help", + "doc-index", + "doc-install", + "doc-security", + "doc-sphinx", + "doc-tor", + ]: + docs_futures = [] + for lang_code in languages: + docs_futures.append(get_docs_translation(component, lang_code)) + + await asyncio.gather(*docs_futures) + + print("") + + await app_percent_output(90) + await app_percent_output(75, 90) + + await docs_percent_output(90) + await docs_percent_output(75, 90) + + +if __name__ == "__main__": + asyncio.run(main()) -- cgit v1.2.3-54-g00ecf From 632862668368655003e38bdcfe4be3e0ddfdce73 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 10 May 2021 18:19:20 -0700 Subject: Fix check-weblate.py to accurately describe the levels of translations --- docs/README.md | 25 ++++++++++++++++++------- docs/check-weblate.py | 35 +++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 21 deletions(-) (limited to 'docs/check-weblate.py') diff --git a/docs/README.md b/docs/README.md index b9f868ec..029217bb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -48,9 +48,13 @@ GET https://hosted.weblate.org/api/translations/onionshare/translations/hr/ GET https://hosted.weblate.org/api/translations/onionshare/translations/eo/ GET https://hosted.weblate.org/api/translations/onionshare/translations/ja/ <...snip...> -GET https://hosted.weblate.org/api/translations/onionshare/doc-tor/he/ | error 404 -GET https://hosted.weblate.org/api/translations/onionshare/doc-tor/en/ -GET https://hosted.weblate.org/api/translations/onionshare/doc-tor/cs/ | error 404 +GET https://hosted.weblate.org/api/translations/onionshare/doc-tor/wo/ | error 404 +GET https://hosted.weblate.org/api/translations/onionshare/doc-tor/ar/ +GET https://hosted.weblate.org/api/translations/onionshare/doc-tor/it/ + +App translations >= 100% +======================= +English (en), 100.0% App translations >= 90% ======================= @@ -62,7 +66,6 @@ Chinese (Traditional) (zh_Hant), 95.0% Croatian (hr), 95.0% Danish (da), 94.5% Dutch (nl), 92.6% -English (en), 100.0% French (fr), 98.0% Galician (gl), 97.5% German (de), 95.0% @@ -84,16 +87,24 @@ Swedish (sv), 94.5% Turkish (tr), 98.0% Ukrainian (uk), 98.0% -App translations >= 75% +App translations >= 80% ======================= Finnish (fi), 88.1% -Docs translations >= 90% +Docs translations >= 100% ======================== English (en), 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0% Turkish (tr), 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0% Ukrainian (uk), 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0% -Docs translations >= 75% +Docs translations >= 90% +======================== + + +Docs translations >= 80% ======================== +German (de), 90.6%, 100.0%, 82.1%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0% +Greek (el), 90.6%, 100.0%, 82.1%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0% +Russian (ru), 90.6%, 100.0%, 82.1%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0% +Spanish (es), 90.6%, 100.0%, 82.1%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0%, 100.0% ``` diff --git a/docs/check-weblate.py b/docs/check-weblate.py index 8283deea..c3e1be03 100755 --- a/docs/check-weblate.py +++ b/docs/check-weblate.py @@ -15,7 +15,9 @@ async def api(path): url = f"https://hosted.weblate.org{path}" async with httpx.AsyncClient() as client: - r = await client.get(url, headers={"Authorization": f"Token {api_token}"}) + r = await client.get( + url, headers={"Authorization": f"Token {api_token}"}, timeout=30.0 + ) if r.status_code == 200: print(f"GET {url}") @@ -41,12 +43,12 @@ async def get_docs_translation(component, lang_code): docs_translations[component][lang_code] = obj["translated_percent"] -async def app_percent_output(percent_min, percent_max=100): +async def app_percent_output(percent_min, percent_max=101): out = [] for lang_code in languages: if ( app_translations[lang_code] >= percent_min - and app_translations[lang_code] <= percent_max + and app_translations[lang_code] < percent_max ): out.append( f"{languages[lang_code]} ({lang_code}), {app_translations[lang_code]}%" @@ -61,7 +63,7 @@ async def app_percent_output(percent_min, percent_max=100): print("") -async def docs_percent_output(percent_min, percent_max=100): +async def docs_percent_output(percent_min, exclude=[]): out = [] for lang_code in languages: include_language = True @@ -74,10 +76,7 @@ async def docs_percent_output(percent_min, percent_max=100): percentages.append(docs_translations[component][lang_code]) - if ( - docs_translations[component][lang_code] < percent_min - or docs_translations[component][lang_code] > percent_max - ): + if docs_translations[component][lang_code] < percent_min: include_language = False break @@ -86,13 +85,19 @@ async def docs_percent_output(percent_min, percent_max=100): percentages = ", ".join(percentages) out.append(f"{languages[lang_code]} ({lang_code}), {percentages}") - out.sort() + excluded = [] + for s in out: + if s not in exclude: + excluded.append(s) + + excluded.sort() print(f"Docs translations >= {percent_min}%") print("========================") - print("\n".join(out)) + print("\n".join(excluded)) print("") + return excluded async def main(): @@ -135,11 +140,13 @@ async def main(): print("") - await app_percent_output(90) - await app_percent_output(75, 90) + await app_percent_output(100) + await app_percent_output(90, 100) + await app_percent_output(80, 90) - await docs_percent_output(90) - await docs_percent_output(75, 90) + out100 = await docs_percent_output(100) + out90 = await docs_percent_output(90, out100) + await docs_percent_output(80, out100 + out90) if __name__ == "__main__": -- cgit v1.2.3-54-g00ecf