Merge pull request #799 from maxthomas/fix-openapi-comment
[mygpo.git] / tools / i18n / generate_commits.py
blobe2c4a6804be7b49de23f5f80f0718c911eb572b5
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # generate_commits.py - Generate Git commits based on Transifex updates
5 # Thomas Perl <thp@gpodder.org>; 2012-08-16
8 import re
9 import glob
10 import subprocess
11 import os.path
13 filenames = []
15 pofiles = os.path.join(
16 os.path.dirname(os.path.abspath(__file__)),
17 "..",
18 "..",
19 "..",
20 "mygpo",
21 "locale",
22 "*",
23 "LC_MESSAGES",
24 "django.po",
27 process = subprocess.Popen(
28 ["git", "status", "--porcelain"] + glob.glob(pofiles), stdout=subprocess.PIPE
30 stdout, stderr = process.communicate()
31 for line in stdout.splitlines():
32 status, filename = line.strip().split()
33 if status == "M":
34 filenames.append(filename)
36 for filename in filenames:
37 in_translators = False
38 translators = []
39 language = None
41 filename = os.path.join("..", "..", filename)
42 for line in open(filename).read().splitlines():
43 if line.startswith("# Translators:"):
44 in_translators = True
45 elif in_translators:
46 match = re.match(r"# ([^<]* <[^>]*>)", line)
47 if match:
48 translators.append(match.group(1))
49 else:
50 in_translators = False
52 match = re.search(r"Last-Translator: ([^<]* <[^>]*>)", line)
53 if match:
54 translators.append(match.group(1))
56 match = re.match(r'"Language-Team: ([^\(]+) \(http://www.transifex.net/', line)
57 if not match:
58 match = re.match(r'"Language-Team: ([^\(]+).*\\n"', line, re.DOTALL)
59 if match:
60 language = match.group(1).strip()
62 if translators and language is not None:
63 if len(translators) != 1:
64 print("# Warning: %d other translators" % (len(translators) - 1,))
65 print(
66 'git commit --author="%s" --message="Updated %s translation" %s'
67 % (translators[0], language, filename)
69 else:
70 print("# FIXME (could not parse):", "!" * 10, filename, "!" * 10)