Backport codecs-aware i18n scripts for use with polib 0.4.2
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 Oct 2009 15:57:33 +0000 (15:57 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 Oct 2009 15:57:33 +0000 (15:57 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_4_0@14562 dcc99617-32d9-48b4-a31d-7c20da2025e4

build/i18n/scripts/db-seed-i18n.py
build/i18n/scripts/dojo_resource.py
build/i18n/scripts/fieldmapper.py
build/i18n/scripts/ils_events.py
build/i18n/scripts/marc_tooltip_maker.py

index d8bd36f..7f34194 100755 (executable)
@@ -152,7 +152,7 @@ def main():
         if not options.outfile:
             outfile = sys.stdout
         else:
-            outfile = open(options.outfile, 'w')
+            outfile = codecs.open(options.outfile, encoding='utf-8', mode='w')
         for insert in pot.sql: 
             outfile.write(insert + "\n")
     else:
index 3134826..6e069e8 100755 (executable)
@@ -7,8 +7,8 @@ Requires polib from http://polib.googlecode.com
 
 Source event definitions are structured as follows:
 {
-    MSG_ID1: "This is a message with 1 variable - ${0}.",
-    MSG_ID2: "This is a message with two variables: ${0} and ${1}."
+    "MSG_ID1": "This is a message with 1 variable - ${0}.",
+    "MSG_ID2": "This is a message with two variables: ${0} and ${1}."
 }
 
 Note that this is a deliberately limited subset of the variable substitution
@@ -28,6 +28,7 @@ allowed by http://api.dojotoolkit.org/jsdoc/dojo/1.2/dojo.string.substitute
 # GNU General Public License for more details.
 
 import basel10n
+import codecs
 import optparse
 import polib
 import re
@@ -57,7 +58,7 @@ class DojoResource (basel10n.BaseL10N):
         # Avoid generating duplicate entries by keeping track of msgids
         msgids = dict()
 
-        bundle = simplejson.load(open(source, 'r'))
+        bundle = simplejson.load(codecs.open(source, encoding='utf-8', mode='r'))
 
         for key, value in bundle.iteritems():
             if value in msgids:
@@ -115,7 +116,7 @@ def main():
         pot.loadpo(options.create)
         pot.create_bundle()
         if options.outfile:
-            outfile = open(options.outfile, 'w')
+            outfile = codecs.open(options.outfile, encoding='utf-8', mode='w')
             simplejson.dump(pot.msgs, outfile, indent=4)
         else:
             print(simplejson.dumps(pot.msgs, indent=4))
index e626d93..385fce5 100755 (executable)
@@ -18,6 +18,7 @@ Requires polib from http://polib.googlecode.com
 # GNU General Public License for more details.
 
 import basel10n
+import codecs
 import optparse
 import polib
 import sys
@@ -182,7 +183,7 @@ def main():
         pot.loadpo(options.entity)
         pot.create_entity()
         if options.outfile:
-            outfile = open(options.outfile, 'w')
+            outfile = codecs.open(options.outfile, encoding='utf-8', mode='w')
             for entity in pot.definitions: 
                 outfile.write(entity + "\n")
         else:
@@ -192,7 +193,7 @@ def main():
     elif options.convert:
         pot.get_strings(options.convert)
         if options.outfile:
-            outfile = open(options.outfile, 'w')
+            outfile = codecs.open(options.outfile, encoding='utf-8', mode='w')
             outfile.write(pot.idl)
         else:
             sys.stdout.write(pot.idl)
index 0efb37d..1b8193c 100755 (executable)
@@ -33,6 +33,7 @@ This generates an updated file with the following structure:
 # GNU General Public License for more details.
 
 import basel10n
+import codecs
 import optparse
 import polib
 import re
@@ -204,7 +205,7 @@ def main():
         pot.loadpo(options.create)
         pot.create_events()
         if options.outfile:
-            outfile = open(options.outfile, 'w')
+            outfile = codecs.open(options.outfile, encoding='utf-8', mode='w')
             outfile.write(head)
             for event in pot.definitions: 
                 outfile.write(event + "\n")
index 3979766..90b6068 100644 (file)
@@ -279,6 +279,7 @@ def process_tag(tag):
     return field
 
 if __name__ == '__main__':
+    import codecs
     import copy
     import os
     import re
@@ -292,7 +293,7 @@ if __name__ == '__main__':
         if (not re.compile(r'^040010-1\d\d\d-f.html').search(filename)):
             continue
         print filename
-        devnull = open('/dev/null', 'w')
+        devnull = codecs.open('/dev/null', encoding='utf-8', mode='w')
         file = subprocess.Popen(
             ('tidy', '-asxml', '-n', '-q', '-utf8', filename),
             stdout=subprocess.PIPE, stderr=devnull).communicate()[0]
@@ -310,6 +311,6 @@ if __name__ == '__main__':
             if (field):
                 ALL_MY_FIELDS.add_field(field)
 
-    MARCOUT = open('marcedit-tooltips-fr.xml', 'w')
+    MARCOUT = codecs.open('marcedit-tooltips-fr.xml', encoding='utf-8', mode='w')
     MARCOUT.write(ALL_MY_FIELDS.to_xml().encode('UTF-8'))
     MARCOUT.close()