Use new weblate API for trim-incomplete-translations

This commit is contained in:
Torsten Grote
2025-05-21 16:20:14 -03:00
parent a1384355f2
commit c6f32fb183
2 changed files with 42 additions and 42 deletions

View File

@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en-US" />
<locale android:name="af" />
<locale android:name="ar" />
<locale android:name="ast" />
<locale android:name="be" />
<locale android:name="bg" />
<locale android:name="bn" />
<locale android:name="bn-BD" />
<locale android:name="ca" />
<locale android:name="cs" />
<locale android:name="cy" />
@@ -24,10 +22,12 @@
<locale android:name="fi" />
<locale android:name="fil" />
<locale android:name="fr" />
<locale android:name="ga" />
<locale android:name="gd" />
<locale android:name="gl" />
<locale android:name="he" />
<locale android:name="hi" />
<locale android:name="hi-Latn" />
<locale android:name="hr" />
<locale android:name="hu" />
<locale android:name="id" />
@@ -39,10 +39,8 @@
<locale android:name="lt" />
<locale android:name="lv" />
<locale android:name="ml" />
<locale android:name="mn" />
<locale android:name="nb" />
<locale android:name="nl" />
<locale android:name="nl-BE" />
<locale android:name="nn" />
<locale android:name="pa" />
<locale android:name="pl" />
@@ -59,7 +57,6 @@
<locale android:name="sv" />
<locale android:name="sw" />
<locale android:name="ta" />
<locale android:name="te" />
<locale android:name="th" />
<locale android:name="tr" />
<locale android:name="uk" />

View File

@@ -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("""<?xml version="1.0" encoding="utf-8"?>
@@ -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))