diff options
| author | tkikuchi | 2005-12-06 04:18:52 +0000 |
|---|---|---|
| committer | tkikuchi | 2005-12-06 04:18:52 +0000 |
| commit | f52e1e76bdfd84ce149148dfe2eda8451d2ce79b (patch) | |
| tree | 2436038c504fc6e6f8540c7a47dd1f2a583ac7de | |
| parent | c4a524d108928720f1acfa73eb18030048ff1e02 (diff) | |
| download | mailman-f52e1e76bdfd84ce149148dfe2eda8451d2ce79b.tar.gz mailman-f52e1e76bdfd84ce149148dfe2eda8451d2ce79b.tar.zst mailman-f52e1e76bdfd84ce149148dfe2eda8451d2ce79b.zip | |
| -rw-r--r-- | bin/Makefile.in | 2 | ||||
| -rwxr-xr-x | bin/po2templ.py | 43 | ||||
| -rwxr-xr-x | bin/templ2pot.py | 117 |
3 files changed, 161 insertions, 1 deletions
diff --git a/bin/Makefile.in b/bin/Makefile.in index dc4eee833..8bb385c9f 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -49,7 +49,7 @@ SCRIPTS= mmsitepass newlist rmlist add_members \ list_admins genaliases change_pw mailmanctl qrunner inject \ unshunt fix_url.py convert.py transcheck b4b5-archfix \ list_owners msgfmt.py show_qfiles discard rb-archfix \ - reset_pw.py + reset_pw.py templ2pot.py po2templ.py BUILDDIR= ../build/bin diff --git a/bin/po2templ.py b/bin/po2templ.py new file mode 100755 index 000000000..c92407364 --- /dev/null +++ b/bin/po2templ.py @@ -0,0 +1,43 @@ +#! @PYTHON@ +# Quick hack by Tokio Kikuchi <tkikuchi@is.kochi-u.ac.jp> + +""" po2templ.py + + extract templates from language po file. + +Usage: po2templ.py languages + +""" + +import sys + +def do_lang(lang): + in_template = 0 + in_msg = 0 + msgstr = '' + for i in file('messages/%s/LC_MESSAGES/mailman.po' % lang): + if i.startswith('#: templates'): + in_template = 1 + in_msg = 0 + filename = i[16:-3] + outfile = file('templates/%s/%s' % (lang, filename), 'w') + continue + if in_template and i.startswith('#,'): + continue + if in_template and i.startswith('msgstr'): + i = i[7:] + in_msg = 1 + if in_msg: + if len(i.strip()) == 0: + in_template = 0 + in_msg = 0 + print >> outfile, msgstr + outfile.close() + msgstr = '' + continue + msgstr += eval(i) + +if __name__ == '__main__': + langs = sys.argv[1:] + for lang in langs: + do_lang(lang) diff --git a/bin/templ2pot.py b/bin/templ2pot.py new file mode 100755 index 000000000..e6f8e0862 --- /dev/null +++ b/bin/templ2pot.py @@ -0,0 +1,117 @@ +#! @PYTHON@ +# Code stolen from pygettext.py +# by Tokio Kikuchi <tkikuchi@is.kochi-u.ac.jp> + +"""templ2pot.py -- convert mailman template (en) to pot format. + +Usage: templ2pot.py inputfile ... + +Options: + + -h, --help + +Inputfiles are english templates. Outputs are written to stdout. + +""" + +import sys +import getopt + +try: + import paths + from Mailman.i18n import _ +except ImportError: + def _(s): return s + +EMPTYSTRING = '' + + +def usage(code, msg=''): + if code: + fd = sys.stderr + else: + fd = sys.stdout + print >> fd, _(__doc__) % globals() + if msg: + print >> fd, msg + sys.exit(code) + + + +escapes = [] + +def make_escapes(pass_iso8859): + global escapes + if pass_iso8859: + # Allow iso-8859 characters to pass through so that e.g. 'msgid + # "H[o-umlaut]he"' would result not result in 'msgid "H\366he"'. + # Otherwise we escape any character outside the 32..126 range. + mod = 128 + else: + mod = 256 + for i in range(256): + if 32 <= (i % mod) <= 126: + escapes.append(chr(i)) + else: + escapes.append("\\%03o" % i) + escapes[ord('\\')] = '\\\\' + escapes[ord('\t')] = '\\t' + escapes[ord('\r')] = '\\r' + escapes[ord('\n')] = '\\n' + escapes[ord('\"')] = '\\"' + + +def escape(s): + global escapes + s = list(s) + for i in range(len(s)): + s[i] = escapes[ord(s[i])] + return EMPTYSTRING.join(s) + + +def normalize(s): + # This converts the various Python string types into a format that is + # appropriate for .po files, namely much closer to C style. + lines = s.split('\n') + if len(lines) == 1: + s = '"' + escape(s) + '"' + else: + if not lines[-1]: + del lines[-1] + lines[-1] = lines[-1] + '\n' + for i in range(len(lines)): + lines[i] = escape(lines[i]) + lineterm = '\\n"\n"' + s = '""\n"' + lineterm.join(lines) + '"' + return s + + + +def main(): + try: + opts, args = getopt.getopt( + sys.argv[1:], + 'h', + ['help',] + ) + except getopt.error, msg: + usage(1, msg) + + # parse options + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + + # calculate escapes + make_escapes(0) + + for filename in args: + print '#: %s:1' % filename + s = file(filename).read() + print '#, template' + print 'msgid', normalize(s) + print 'msgstr ""\n' + + +if __name__ == '__main__': + main() |
