From c6f32fb183caee45f0f89ea831850f607dbf86af Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 21 May 2025 16:20:14 -0300 Subject: [PATCH] Use new weblate API for trim-incomplete-translations --- app/src/main/res/xml/locales_config.xml | 7 +- ...rim-incomplete-translations-for-release.py | 77 ++++++++++--------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/app/src/main/res/xml/locales_config.xml b/app/src/main/res/xml/locales_config.xml index ffbb40e28..36ffa9cd9 100644 --- a/app/src/main/res/xml/locales_config.xml +++ b/app/src/main/res/xml/locales_config.xml @@ -1,13 +1,11 @@ - - @@ -24,10 +22,12 @@ + + @@ -39,10 +39,8 @@ - - @@ -59,7 +57,6 @@ - diff --git a/tools/trim-incomplete-translations-for-release.py b/tools/trim-incomplete-translations-for-release.py index 1375721d0..503c33e96 100755 --- a/tools/trim-incomplete-translations-for-release.py +++ b/tools/trim-incomplete-translations-for-release.py @@ -19,45 +19,47 @@ repo = git.Repo(projectbasedir) msg = 'removing all translations less than 70% complete\n\n' -url = 'https://hosted.weblate.org/exports/stats/f-droid/f-droid/?format=csv' +url = 'https://hosted.weblate.org/api/components/f-droid/f-droid/statistics/' r = requests.get(url) -stats = csv.reader(r.iter_lines(decode_unicode=True), delimiter=',') -next(stats) # skip CSV header +stats = r.json()["results"] locales_config = set() for row in stats: - if len(row) > 4: - locale = row[1] - if float(row[4]) > 70.0: - if locale == 'nb_NO': - locale = 'nb' - elif locale == 'yue_Hant': - locale = 'yue' - elif locale == 'zh_Hans': - locale = 'zh-CN' - elif locale == 'zh_Hant': - locale = 'zh-TW' - elif locale == 'zh_Hant_HK': - locale = 'zh-HK' - locales_config.add(locale.replace('_', '-')) - continue - if '_' in locale: - codes = locale.split('_') - if codes[1] == 'Hans': - codes[1] = 'CN' - elif codes[1] == 'Hant': - codes[1] = 'TW' - locale = codes[0] + '-r' + codes[1] - translation_file = 'app/src/main/res/values-' + locale + '/strings.xml' - percent = str(int(float(row[4]))) + '%' - print('Removing incomplete file: (' + percent + ')\t', - translation_file) - delfile = os.path.join(projectbasedir, translation_file) - if os.path.exists(delfile): - os.remove(delfile) - repo.index.remove([translation_file, ]) - if len(percent) == 2: - msg += ' ' - msg += percent + ' ' + row[1] + ' ' + row[0] + '\n' + locale = row["code"] + translated_percent = float(row["translated_percent"]) + if translated_percent > 70.0: + if locale == 'nb_NO': + locale = 'nb' + elif locale == 'yue_Hant': + locale = 'yue' + elif locale == 'zh_Hans': + locale = 'zh-CN' + elif locale == 'zh_Hant': + locale = 'zh-TW' + elif locale == 'zh_Hant_HK': + locale = 'zh-HK' + locales_config.add(locale.replace('_', '-')) + continue + if '_' in locale: + codes = locale.split('_') + if codes[1] == 'Hans': + codes[1] = 'CN' + elif codes[1] == 'Hant': + codes[1] = 'TW' + locale = codes[0] + '-r' + codes[1] + translation_file = 'app/src/main/res/values-' + locale + '/strings.xml' + percent = str(int(translated_percent)) + '%' + print('Removing incomplete file: (' + percent + ')\t', + translation_file) + delfile = os.path.join(projectbasedir, translation_file) + if os.path.exists(delfile): + os.remove(delfile) + repo.index.remove([translation_file, ]) + if len(percent) == 2: + msg += ' ' + msg += percent + ' ' + locale + ' ' + row['name'] + '\n' + +if len(locales_config) == 0: + print("ERROR: Did not get any locales") with open('app/src/main/res/xml/locales_config.xml', 'w') as fp: fp.write(""" @@ -79,4 +81,5 @@ if not found: print('ERROR: there must be a weblate remote to preserve incomplete translations!') sys.exit(1) -repo.index.commit(msg) +commit = repo.index.commit(msg) +print('Commited: ' + commit.summary + ' ' + str(commit))