use unicode strings for Flattr thing description
[mygpo.git] / tools / i18n / generate_commits.py
blobed92aa5280b44d2c536c31c4be13f523c10d8fd3
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 process = subprocess.Popen(['git', 'status', '--porcelain'] +
16 glob.glob('../../mygpo/locale/*/LC_MESSAGES/django.po'), stdout=subprocess.PIPE)
17 stdout, stderr = process.communicate()
18 for line in stdout.splitlines():
19 status, filename = line.strip().split()
20 if status == 'M':
21 filenames.append(filename)
23 for filename in filenames:
24 in_translators = False
25 translators = []
26 language = None
28 filename = os.path.join('..', '..', filename)
29 for line in open(filename).read().splitlines():
30 if line.startswith('# Translators:'):
31 in_translators = True
32 elif in_translators:
33 match = re.match(r'# ([^<]* <[^>]*>)', line)
34 if match:
35 translators.append(match.group(1))
36 else:
37 in_translators = False
39 match = re.search(r'Last-Translator: ([^<]* <[^>]*>)', line)
40 if match:
41 translators.append(match.group(1))
43 match = re.match(r'"Language-Team: ([^\(]+) \(http://www.transifex.net/', line)
44 if not match:
45 match = re.match(r'"Language-Team: ([^\(]+).*\\n"', line, re.DOTALL)
46 if match:
47 language = match.group(1).strip()
49 if translators and language is not None:
50 if len(translators) != 1:
51 print '# Warning: %d other translators' % (len(translators) - 1,)
52 print 'git commit --author="%s" --message="Updated %s translation" %s' % (translators[0], language, filename)
53 else:
54 print '# FIXME (could not parse):', '!'*10, filename, '!'*10