2021-05-10 21:05:41 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
import httpx
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
api_token = None
|
|
|
|
languages = {}
|
|
|
|
app_translations = {}
|
|
|
|
docs_translations = {}
|
|
|
|
|
|
|
|
|
|
|
|
async def api(path):
|
|
|
|
url = f"https://hosted.weblate.org{path}"
|
|
|
|
|
2021-11-26 13:51:30 -05:00
|
|
|
# Wait a bit before each API call, to avoid hammering the server and
|
|
|
|
# getting temporarily blocked
|
|
|
|
await asyncio.sleep(1)
|
|
|
|
|
2021-05-10 21:05:41 -04:00
|
|
|
async with httpx.AsyncClient() as client:
|
2021-05-10 21:19:20 -04:00
|
|
|
r = await client.get(
|
2021-11-23 22:33:21 -05:00
|
|
|
url, headers={"Authorization": f"Token {api_token}"}, timeout=60
|
2021-05-10 21:19:20 -04:00
|
|
|
)
|
2021-05-10 21:05:41 -04:00
|
|
|
|
|
|
|
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"]
|
|
|
|
|
|
|
|
|
2021-05-10 21:19:20 -04:00
|
|
|
async def app_percent_output(percent_min, percent_max=101):
|
2021-05-10 21:05:41 -04:00
|
|
|
out = []
|
|
|
|
for lang_code in languages:
|
|
|
|
if (
|
2023-09-04 23:16:44 -04:00
|
|
|
lang_code in app_translations
|
|
|
|
and app_translations[lang_code] >= percent_min
|
2021-05-10 21:19:20 -04:00
|
|
|
and app_translations[lang_code] < percent_max
|
2021-05-10 21:05:41 -04:00
|
|
|
):
|
|
|
|
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("")
|
|
|
|
|
|
|
|
|
2021-10-03 17:09:07 -04:00
|
|
|
async def docs_percent_output(percent_min, percent_max=101):
|
2021-05-10 21:05:41 -04:00
|
|
|
out = []
|
|
|
|
for lang_code in languages:
|
|
|
|
percentages = []
|
|
|
|
|
|
|
|
for component in docs_translations:
|
2021-10-03 17:09:07 -04:00
|
|
|
if lang_code in docs_translations[component]:
|
|
|
|
percentages.append(docs_translations[component][lang_code])
|
|
|
|
else:
|
|
|
|
percentages.append(0)
|
2021-05-10 21:05:41 -04:00
|
|
|
|
2021-10-03 17:09:07 -04:00
|
|
|
average_percentage = int(sum(percentages) / len(percentages))
|
2021-05-10 21:05:41 -04:00
|
|
|
|
2021-10-03 17:09:07 -04:00
|
|
|
if (
|
|
|
|
average_percentage != 0
|
|
|
|
and average_percentage >= percent_min
|
|
|
|
and average_percentage < percent_max
|
|
|
|
):
|
|
|
|
out.append(f"{languages[lang_code]} ({lang_code}), {average_percentage}%")
|
2021-05-10 21:19:20 -04:00
|
|
|
|
2021-10-03 17:09:07 -04:00
|
|
|
out.sort()
|
2021-05-10 21:05:41 -04:00
|
|
|
|
|
|
|
print(f"Docs translations >= {percent_min}%")
|
|
|
|
print("========================")
|
2021-10-03 17:09:07 -04:00
|
|
|
print("\n".join(out))
|
2021-05-10 21:05:41 -04:00
|
|
|
|
|
|
|
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:
|
2023-09-04 22:13:28 -04:00
|
|
|
languages[obj["code"]] = obj["name"]
|
2021-05-10 21:05:41 -04:00
|
|
|
|
|
|
|
# Get the app translations for each language
|
2021-11-23 22:33:21 -05:00
|
|
|
for lang_code in languages:
|
|
|
|
await get_app_translation(lang_code)
|
2021-05-10 21:05:41 -04:00
|
|
|
|
|
|
|
# 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",
|
|
|
|
]:
|
|
|
|
for lang_code in languages:
|
2021-11-23 22:33:21 -05:00
|
|
|
await get_docs_translation(component, lang_code)
|
2021-05-10 21:05:41 -04:00
|
|
|
|
|
|
|
print("")
|
|
|
|
|
2021-09-26 14:41:01 -04:00
|
|
|
await app_percent_output(90, 101)
|
2021-10-03 17:09:07 -04:00
|
|
|
await app_percent_output(50, 90)
|
|
|
|
await app_percent_output(0, 50)
|
2021-05-10 21:05:41 -04:00
|
|
|
|
2021-10-03 17:09:07 -04:00
|
|
|
await docs_percent_output(90, 101)
|
|
|
|
await docs_percent_output(50, 90)
|
|
|
|
await docs_percent_output(0, 50)
|
2021-05-10 21:05:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
asyncio.run(main())
|