summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2005-12-30 18:51:17 +0000
committerbwarsaw2005-12-30 18:51:17 +0000
commit2c1d1dc75772f830222b16e037b8185bcfbf920e (patch)
tree54fda904b6ff5e407b020d67954341600dc9a38c
parent5d1b56a08974788ed44101bcc6f3e38464e7cd37 (diff)
downloadmailman-2c1d1dc75772f830222b16e037b8185bcfbf920e.tar.gz
mailman-2c1d1dc75772f830222b16e037b8185bcfbf920e.tar.zst
mailman-2c1d1dc75772f830222b16e037b8185bcfbf920e.zip
-rwxr-xr-xbin/po2templ.py96
1 files changed, 63 insertions, 33 deletions
diff --git a/bin/po2templ.py b/bin/po2templ.py
index 769611e95..432c81d28 100755
--- a/bin/po2templ.py
+++ b/bin/po2templ.py
@@ -1,51 +1,81 @@
#! @PYTHON@
-# Quick hack by Tokio Kikuchi <tkikuchi@is.kochi-u.ac.jp>
+#
+# Copyright (C) 2005 by the Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
-""" po2templ.py
+# Author: Tokio Kikuchi <tkikuchi@is.kochi-u.ac.jp>
- extract templates from language po file.
-Usage: po2templ.py languages
+"""po2templ.py
+
+Extract templates from language po file.
+Usage: po2templ.py languages
"""
import sys
+
+
def do_lang(lang):
- in_template = 0
- in_msg = 0
+ in_template = False
+ in_msg = False
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]
- outfilename = 'templates/%s/%s' % (lang, filename)
- 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
- if (len(msgstr) > 1) and outfilename:
- # exclude no translation ... only one LF.
- outfile = file(outfilename, 'w')
- print >> outfile, msgstr
- outfile.close()
- outfilename = ''
- msgstr = ''
+ fp = file('messages/%s/LC_MESSAGES/mailman.po' % lang)
+ try:
+ for line in fp:
+ if line.startswith('#: templates'):
+ in_template = True
+ in_msg = False
+ filename = line[16:-3]
+ outfilename = 'templates/%s/%s' % (lang, filename)
+ continue
+ if in_template and line.startswith('#,'):
continue
- msgstr += eval(i)
- if (msgstr > 1) and outfilename:
+ if in_template and line.startswith('msgstr'):
+ line = line[7:]
+ in_msg = True
+ if in_msg:
+ if not line.strip():
+ in_template = False
+ in_msg = False
+ if len(msgstr) > 1 and outfilename:
+ # exclude no translation ... only one LF.
+ outfile = file(outfilename, 'w')
+ try:
+ outfile.write(msgstr)
+ finally:
+ outfile.close()
+ outfilename = ''
+ msgstr = ''
+ continue
+ msgstr += eval(i)
+ finally:
+ fp.close()
+ if msgstr > 1 and outfilename:
# flush remaining msgstr
outfile = file(outfilename, 'w')
- print >> outfile, msgstr
- outfile.close()
+ try:
+ outfile.write(msgstr)
+ finally:
+ outfile.close()
+
+
if __name__ == '__main__':
langs = sys.argv[1:]
for lang in langs: