2017-12-22 09:09:55 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from subprocess import check_output
|
|
|
|
|
2024-11-14 01:30:36 +01:00
|
|
|
import orjson
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-12-22 09:09:55 +01:00
|
|
|
def get_json_filename(locale: str) -> str:
|
2020-06-09 00:25:09 +02:00
|
|
|
return f"locale/{locale}/mobile.json"
|
2017-12-22 09:09:55 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def get_locales() -> list[str]:
|
2022-01-22 07:52:54 +01:00
|
|
|
output = check_output(["git", "ls-files", "locale"], text=True)
|
2020-10-30 01:36:18 +01:00
|
|
|
tracked_files = output.split()
|
2021-02-12 08:20:45 +01:00
|
|
|
regex = re.compile(r"locale/(\w+)/LC_MESSAGES/django.po")
|
|
|
|
locales = ["en"]
|
2017-12-22 09:09:55 +01:00
|
|
|
for tracked_file in tracked_files:
|
|
|
|
matched = regex.search(tracked_file)
|
|
|
|
if matched:
|
|
|
|
locales.append(matched.group(1))
|
|
|
|
|
|
|
|
return locales
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def get_translation_stats(resource_path: str) -> dict[str, int]:
|
2024-11-14 01:30:36 +01:00
|
|
|
with open(resource_path, "rb") as raw_resource_file:
|
|
|
|
raw_info = orjson.loads(raw_resource_file.read())
|
2017-12-22 09:09:55 +01:00
|
|
|
|
|
|
|
total = len(raw_info)
|
2021-02-12 08:20:45 +01:00
|
|
|
not_translated = len([i for i in raw_info.items() if i[1] == ""])
|
|
|
|
return {"total": total, "not_translated": not_translated}
|
2017-12-22 09:09:55 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
translation_stats: dict[str, dict[str, int]] = {}
|
2017-12-22 09:09:55 +01:00
|
|
|
locale_paths = [] # List[str]
|
|
|
|
for locale in get_locales():
|
|
|
|
path = get_json_filename(locale)
|
|
|
|
if os.path.exists(path):
|
2018-06-18 02:37:29 +02:00
|
|
|
stats = get_translation_stats(path)
|
|
|
|
translation_stats.update({locale: stats})
|
2017-12-22 09:09:55 +01:00
|
|
|
locale_paths.append(path)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
stats_path = os.path.join("locale", "mobile_info.json")
|
2024-11-14 01:30:36 +01:00
|
|
|
with open(stats_path, "wb") as f:
|
|
|
|
f.write(
|
|
|
|
orjson.dumps(
|
|
|
|
translation_stats,
|
|
|
|
option=orjson.OPT_APPEND_NEWLINE | orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS,
|
|
|
|
)
|
|
|
|
)
|
2017-12-22 09:09:55 +01:00
|
|
|
|
2018-06-18 02:37:29 +02:00
|
|
|
print("Mobile stats file created at: " + stats_path)
|