aboutsummaryrefslogtreecommitdiff
path: root/doc/tutorials/start-here/po/generate-pot.py
blob: 890a57e2fc33fc724c0488562deea76f2cda8c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python

import re

f = open('../+start-here.pd', 'r')
text = ''
for line in f.readlines():
    text += line

print """# SOME DESCRIPTIVE TITLE.
# This file is put in the public domain.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Pure Data 0.43\\n"
"Report-Msgid-Bugs-To: http://bugs.puredata.info\\n"
"POT-Creation-Date: 2012-12-31 20:40-0500\\n"
"PO-Revision-Date: 2012-12-31 20:45-0500\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <LL@li.org>\\n"
"Language: \\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=utf-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"""

regex = re.compile('#X text [0-9]+ [0-9]+ ([^;]*);', re.MULTILINE | re.DOTALL)
matches = [m.groups() for m in regex.finditer(text)]

nonewlines = re.compile('\n', re.MULTILINE)
nobackslashes = re.compile(' \\\\', re.MULTILINE)
escapedoublequote = re.compile('[^\\\\]"', re.MULTILINE)

ids = []
for m in matches:
    if m:
        chunk = m[0]
        chunk = re.sub(nonewlines, ' ', chunk)
        chunk = re.sub(nobackslashes, '', chunk)
        chunk = re.sub(escapedoublequote, '\\"', chunk)
        if chunk not in ids:
            ids.append(chunk)

for id in ids:
        print '\nmsgid "' + id + '"'
        print 'msgstr ""'