[Checkins] SVN: zope.app.locales/trunk/ Bugfix: handle Unicode msgids and default values.

Marius Gedminas marius at pov.lt
Mon Dec 12 13:32:23 UTC 2011


Log message for revision 123756:
  Bugfix: handle Unicode msgids and default values.
  
  Previously, running bin/i18nextract would take messages like, e.g.
  
    <configure i18n_domain="myapp">
      <class class=".app.MyApp">
        <factory title="Something &#x263B;" ...
  
  and fail with IndexError or, if the Unicode characters were in the Latin-1
  subset, encode them as Latin-1 in a .pot file that declared its charset to be
  UTF-8.
  
  

Changed:
  U   zope.app.locales/trunk/CHANGES.txt
  U   zope.app.locales/trunk/src/zope/app/locales/extract.py

-=-
Modified: zope.app.locales/trunk/CHANGES.txt
===================================================================
--- zope.app.locales/trunk/CHANGES.txt	2011-12-12 13:28:51 UTC (rev 123755)
+++ zope.app.locales/trunk/CHANGES.txt	2011-12-12 13:32:23 UTC (rev 123756)
@@ -5,7 +5,7 @@
 3.7.2 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- Handle Unicode msgids and default values.
 
 
 3.7.1 (2011-12-07)

Modified: zope.app.locales/trunk/src/zope/app/locales/extract.py
===================================================================
--- zope.app.locales/trunk/src/zope/app/locales/extract.py	2011-12-12 13:28:51 UTC (rev 123755)
+++ zope.app.locales/trunk/src/zope/app/locales/extract.py	2011-12-12 13:32:23 UTC (rev 123756)
@@ -96,6 +96,16 @@
     msgid "test"
     msgstr ""
     <BLANKLINE>
+
+    Unicode can be used in msgids and default values
+
+    >>> entry = POTEntry(Message(u"\u263B", default=u"\u253A"))
+    >>> entry.write(FakeFile())
+    #. Default: "\342\224\272"
+    msgid "\342\230\273"
+    msgstr ""
+    <BLANKLINE>
+
     """
 
     implements(IPOTEntry)
@@ -116,13 +126,13 @@
             file.write(self.comments)
         if (isinstance(self.msgid, Message) and
             self.msgid.default is not None):
-            default = self.msgid.default.strip()
+            default = self.msgid.default.strip().encode(DEFAULT_CHARSET)
             lines = normalize(default).split("\n")
             lines[0] = "#. Default: %s\n" % lines[0]
             for i in range(1, len(lines)):
                 lines[i] = "#.  %s\n" % lines[i]
             file.write("".join(lines))
-        file.write('msgid %s\n' % normalize(self.msgid))
+        file.write('msgid %s\n' % normalize(self.msgid.encode(DEFAULT_CHARSET)))
         file.write('msgstr ""\n')
         file.write('\n')
 



More information about the checkins mailing list