Browse Source

script to automatically cherry-pick complete translations from Weblate

This creates a branch 'merge_weblate' and cherry picks commits from Weblate
that contain 100% complete translations.
tags/1.7-alpha0
Hans-Christoph Steiner 1 month ago
parent
commit
826d70f2c9
1 changed files with 82 additions and 0 deletions
  1. 82
    0
      tools/pick-complete-translations.py

+ 82
- 0
tools/pick-complete-translations.py View File

@@ -0,0 +1,82 @@
1
+#!/usr/bin/python3
2
+#
3
+# cherry-pick complete translations from weblate
4
+
5
+import git
6
+import json
7
+import os
8
+import re
9
+import requests
10
+import sys
11
+
12
+
13
+def get_paths_tuple(locale):
14
+    return (
15
+        'metadata/%s/*.txt' % locale,
16
+        'metadata/%s/changelogs/*.txt' % locale,
17
+        'app/src/main/res/values-%s/strings.xml' % re.sub(r'-', r'-r', locale),
18
+    )
19
+
20
+projectbasedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
21
+print(projectbasedir)
22
+
23
+repo = git.Repo(projectbasedir)
24
+weblate = repo.remotes.weblate
25
+weblate.fetch()
26
+upstream = repo.remotes.upstream
27
+upstream.fetch()
28
+
29
+url = 'https://hosted.weblate.org/exports/stats/f-droid/f-droid/?format=json'
30
+r = requests.get(url)
31
+r.raise_for_status()
32
+app = r.json()
33
+
34
+url = 'https://hosted.weblate.org/exports/stats/f-droid/f-droid-metadata/?format=json'
35
+r = requests.get(url)
36
+r.raise_for_status()
37
+metadata = r.json()
38
+
39
+
40
+#with open('f-droid-metadata.json') as fp:
41
+#    metadata = json.load(fp)
42
+
43
+app_locales = dict()
44
+metadata_locales = dict()
45
+
46
+merge_locales = []
47
+for locale in app:
48
+    app_locales[locale['code']] = locale
49
+for locale in metadata:
50
+    metadata_locales[locale['code']] = locale
51
+
52
+for locale in sorted(app_locales.keys(), reverse=True):
53
+    a = app_locales.get(locale)
54
+    m = metadata_locales.get(locale)
55
+    if a is not None and a['translated_percent'] == 100 and a['failing'] == 0 \
56
+       and m is not None and m['translated_percent'] == 100 and m['failing'] == 0:
57
+        print(locale)
58
+        merge_locales.append(locale)
59
+
60
+if not merge_locales:
61
+    sys.exit()
62
+
63
+if 'merge_weblate' in repo.heads:
64
+    merge_weblate = repo.heads['merge_weblate']
65
+    repo.create_tag('previous_merge_weblate', ref=merge_weblate,
66
+                    message=('Automatically created by %s' % __file__))
67
+else:
68
+    merge_weblate = repo.create_head('merge_weblate')
69
+merge_weblate.set_commit(upstream.refs.master)
70
+merge_weblate.checkout()
71
+
72
+email_pattern = re.compile(r'by (.*?) <(.*)>$')
73
+
74
+for locale in sorted(merge_locales):
75
+    commits = list(repo.iter_commits(
76
+        str(weblate.refs.master) + '...' + str(upstream.refs.master),
77
+        paths=get_paths_tuple(locale), max_count=10))
78
+    for commit in reversed(commits):
79
+        repo.git.cherry_pick(str(commit))
80
+        m = email_pattern.search(commit.summary)
81
+        if m:
82
+            email = m.group(1) + ' <' + m.group(2) + '>'

Loading…
Cancel
Save