1 | #!/usr/bin/python
|
---|
2 |
|
---|
3 | from glob import glob
|
---|
4 |
|
---|
5 | FILES = '%s/LC_MESSAGES/django.po'
|
---|
6 | FORMATS = 'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT', 'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT'
|
---|
7 |
|
---|
8 | EN = 'en'
|
---|
9 | OUTPUT = '\nmsgid "%s"\nmsgstr "%s"\n'
|
---|
10 |
|
---|
11 | data = {}
|
---|
12 |
|
---|
13 | for file in glob(FILES % '*'):
|
---|
14 | language = file.split('/')[0]
|
---|
15 | data[language] = {}
|
---|
16 | format = None
|
---|
17 | for line in open(file):
|
---|
18 | try:
|
---|
19 | content = line.strip().split(None, 1)[1].strip('"')
|
---|
20 | if format:
|
---|
21 | if content and content != format:
|
---|
22 | data[language][format] = content
|
---|
23 | format = None
|
---|
24 | elif content in FORMATS:
|
---|
25 | format = content
|
---|
26 | except:
|
---|
27 | pass
|
---|
28 |
|
---|
29 | for language in data:
|
---|
30 | file = open(FILES % language, 'a')
|
---|
31 | for format in FORMATS:
|
---|
32 | key = data[EN][format]
|
---|
33 | value = data[language].get(format, key)
|
---|
34 | file.write(OUTPUT % (key, value))
|
---|
35 | file.close()
|
---|