1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-06-30 14:40:09 +02:00

script to set the completed locales based on Weblate data

This commit is contained in:
Hans-Christoph Steiner 2021-01-16 15:12:01 +01:00
parent 527b1caa90
commit 5837c36219
3 changed files with 56 additions and 1 deletions

View File

@ -34,6 +34,7 @@ include locale/pl/LC_MESSAGES/fdroidserver.mo
include locale/pt_BR/LC_MESSAGES/fdroidserver.mo
include locale/pt_PT/LC_MESSAGES/fdroidserver.mo
include locale/ru/LC_MESSAGES/fdroidserver.mo
include locale/sq/LC_MESSAGES/fdroidserver.mo
include locale/tr/LC_MESSAGES/fdroidserver.mo
include locale/uk/LC_MESSAGES/fdroidserver.mo
include locale/zh_Hans/LC_MESSAGES/fdroidserver.mo

View File

@ -5,7 +5,7 @@ FILES = ../fdroid $(wildcard ../fdroidserver/*.py) \
$(wildcard /usr/lib/python3.*/getopt.py)
# these are the supported languages
ALL_LINGUAS = bo de es fr hu it ko nb_NO pl pt_BR pt_PT ru tr uk zh_Hans zh_Hant
ALL_LINGUAS = $(shell sed -En 's,include locale/([^/]+)/.*,\1,p' ../MANIFEST.in)
POFILES = $(wildcard */LC_MESSAGES/fdroidserver.po)
MOFILES = $(ALL_LINGUAS:=/LC_MESSAGES/fdroidserver.mo)

View File

@ -0,0 +1,54 @@
#!/usr/bin/python3
#
# add completed translations from weblate to MANIFEST.in
import json
import os
import re
import requests
import sys
projectbasedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
localedir = os.path.join(projectbasedir, 'locale')
print(projectbasedir)
cached_file = os.path.join(localedir, 'fdroidserver.json')
if os.path.exists(cached_file):
with open(cached_file) as fp:
data = json.load(fp)
else:
url = 'https://hosted.weblate.org/exports/stats/f-droid/fdroidserver/?format=json'
r = requests.get(url)
r.raise_for_status()
data = r.json()
active = set()
print('name locale translated approved error-free')
for locale in sorted(data, key=lambda locale: locale['code']):
print('%26s' % locale['name'],
'%8s' % locale['code'],
'%0.1f%%' % locale['translated_percent'],
'%0.1f%%' % locale['approved_percent'],
'%0.1f%%' % (100 - locale['failing_percent']),
sep='\t')
if locale['translated_percent'] >= 90 and locale['failing'] < 5:
active.add(locale['code'])
manifest_file = os.path.join(projectbasedir, 'MANIFEST.in')
with open(manifest_file) as fp:
for line in fp.readlines():
m = re.match(r'include locale/([^/]+)/.*', line)
if m:
active.add(m.group(1))
manifest_lines = set()
for locale in active:
manifest_lines.add('include locale/%s/LC_MESSAGES/fdroidserver.mo\n' % locale)
with open(manifest_file, 'a') as fp:
for line in manifest_lines:
if line:
fp.write(line)
os.system('sort -u -o %s %s' % (manifest_file, manifest_file))