comparison contrib/gettext_parser/gettext.py @ 0:77665d8e2254

tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0 (automatically generated log message) imported from: moin--main--1.5--base-0
author Thomas Waldmann <tw-public@gmx.de>
date Thu, 22 Sep 2005 15:09:50 +0000
parents
children 01f05e74aa9c
comparison
equal deleted inserted replaced
-1:000000000000 0:77665d8e2254
1 # -*- coding: iso-8859-15 -*-
2 """
3 MoinMoin - GetText .po parser for moin 1.3.x
4
5 Usage:
6 ======
7
8 Either begin your page like this:
9 #format gettext
10 (followed by .po file content only)
11
12 Or attach the .po file and inline it:
13 ... (wiki markup) ...
14 inline:de.po
15 ... (wiki markup) ...
16
17 Of course, if you just attach the file, you won't be able to edit it in
18 the wiki. So the #format method is better for online editing.
19
20 Requirements:
21 =============
22
23 * requires Python 2.4 and installed "gettext" package (msgfmt)
24 * requires wiki page content to be in config.charset, so do not put non-
25 utf-8 content into a utf-8 wiki or it will crash.
26
27 @copyright: 2005 by MoinMoin:AlexanderSchremmer
28 @license: GNU GPL, see COPYING for details.
29 """
30
31 Dependencies = []
32
33 import subprocess
34 from MoinMoin import config
35
36 class Parser:
37 extensions = ['.po']
38 def __init__ (self, raw, request, **kw):
39 self.raw = raw
40 self.request = request
41
42 def format(self, formatter):
43 PIPE = subprocess.PIPE
44 STDOUT = subprocess.STDOUT
45 p = subprocess.Popen(("msgfmt", "-c", "--statistics", "-",), shell=False,
46 stdin=PIPE, stdout=PIPE, stderr=STDOUT)
47
48 charset = config.charset
49 textin = self.raw.encode(charset)
50 out = p.communicate(input=textin)[0]
51 if out is None:
52 out = ''
53 out = out.decode(charset).replace('<stdin>:', 'input data line ')
54
55 # show po file data with line numbers as msgfmt refers to them
56 text, lineno = [], 0
57 for l in self.raw.splitlines():
58 lineno += 1
59 text.append("%04d: %s" % (lineno, l))
60
61 textout = [formatter.heading(1, 3),
62 'Gettext status messages:',
63 formatter.heading(0, 3),
64 formatter.preformatted(1),
65 formatter.text(out),
66 formatter.preformatted(0),
67 formatter.heading(1, 3),
68 'Input:',
69 formatter.heading(0, 3),
70 formatter.preformatted(1),
71 formatter.text("\n".join(text)),
72 formatter.preformatted(0),
73 ]
74
75 self.request.write(''.join(textout))