From 5837c36219232074a0e2e30e6d7442e922dddb9c Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 16 Jan 2021 15:12:01 +0100 Subject: [PATCH] script to set the completed locales based on Weblate data --- MANIFEST.in | 1 + locale/Makefile | 2 +- locale/pick-complete-translations.py | 54 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 locale/pick-complete-translations.py diff --git a/MANIFEST.in b/MANIFEST.in index 19ac48e8..48e4830a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/locale/Makefile b/locale/Makefile index 1dd27274..d181db1d 100644 --- a/locale/Makefile +++ b/locale/Makefile @@ -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) diff --git a/locale/pick-complete-translations.py b/locale/pick-complete-translations.py new file mode 100755 index 00000000..8c3eead1 --- /dev/null +++ b/locale/pick-complete-translations.py @@ -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))