2017-12-22 09:09:55 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from subprocess import check_output
|
|
|
|
from typing import Dict, List
|
|
|
|
|
|
|
|
def get_json_filename(locale: str) -> str:
|
|
|
|
return "static/locale/{}/mobile.json".format(locale)
|
|
|
|
|
|
|
|
def get_locales() -> List[str]:
|
|
|
|
tracked_files = check_output(['git', 'ls-files', 'static/locale'])
|
|
|
|
tracked_files = tracked_files.decode().split()
|
|
|
|
regex = re.compile('static/locale/(\w+)/LC_MESSAGES/django.po')
|
|
|
|
locales = ['en']
|
|
|
|
for tracked_file in tracked_files:
|
|
|
|
matched = regex.search(tracked_file)
|
|
|
|
if matched:
|
|
|
|
locales.append(matched.group(1))
|
|
|
|
|
|
|
|
return locales
|
|
|
|
|
2018-06-18 02:37:29 +02:00
|
|
|
def get_translation_stats(resource_path: str) -> Dict[str, int]:
|
2017-12-22 09:09:55 +01:00
|
|
|
with open(resource_path) as raw_resource_file:
|
|
|
|
raw_info = json.load(raw_resource_file)
|
|
|
|
|
|
|
|
total = len(raw_info)
|
|
|
|
not_translated = len([i for i in raw_info.items() if i[1] == ''])
|
|
|
|
return {'total': total, 'not_translated': not_translated}
|
|
|
|
|
2018-06-18 02:37:29 +02:00
|
|
|
translation_stats = {} # type: 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)
|
|
|
|
|
2018-06-18 02:37:29 +02:00
|
|
|
stats_path = os.path.join('static', 'locale', 'mobile_info.json')
|
|
|
|
with open(stats_path, 'w') as f:
|
|
|
|
json.dump(translation_stats, f, indent=2, sort_keys=True)
|
2017-12-22 09:09:55 +01:00
|
|
|
f.write('\n')
|
|
|
|
|
2018-06-18 02:37:29 +02:00
|
|
|
print("Mobile stats file created at: " + stats_path)
|