diff --git a/CHANGES.txt b/CHANGES.txt index 0009ae9..4513d1e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,10 @@ CHANGES 3.7.4 (unreleased) ------------------ +- In version 3.7.2 msgids and default values where forced to be + unicodes. This was too strict because at least the TAL extractor returns + UTF-8 encoded default values. Fixed this by allowing the default value to + be a string again. 3.7.3 (2012-01-06) diff --git a/src/zope/app/locales/extract.py b/src/zope/app/locales/extract.py index a9fab41..b2e5a5f 100644 --- a/src/zope/app/locales/extract.py +++ b/src/zope/app/locales/extract.py @@ -97,7 +97,7 @@ class POTEntry(object): msgstr "" - Unicode can be used in msgids and default values + Unicode can be used in msgids and default values: >>> entry = POTEntry(Message(u"\u263B", default=u"\u253A")) >>> entry.write(FakeFile()) @@ -106,6 +106,16 @@ class POTEntry(object): msgstr "" + But msgid might be an ascii encoded string and `default` might be a + string with the DEFAULT_ENCODING, too: + + >>> entry = POTEntry(Message("Oe", default="\xd6")) + >>> entry.write(FakeFile()) + #. Default: "\326" + msgid "Oe" + msgstr "" + + """ implements(IPOTEntry) @@ -130,7 +140,9 @@ def write(self, file): file.write('#: %s:%s\n' % (filename, line)) if (isinstance(self.msgid, Message) and self.msgid.default is not None): - default = self.msgid.default.strip().encode(DEFAULT_CHARSET) + default = self.msgid.default.strip() + if isinstance(default, unicode): + default = default.encode(DEFAULT_CHARSET) lines = normalize(default).split("\n") lines[0] = "#. Default: %s\n" % lines[0] for i in range(1, len(lines)): @@ -181,7 +193,7 @@ def _getProductVersion(self): def write(self): file = open(self._output_filename, 'w') - file.write(pot_header % {'time': time.ctime(), + file.write(pot_header % {'time': time.ctime(), 'version': self._getProductVersion(), 'charset': DEFAULT_CHARSET, 'encoding': DEFAULT_ENCODING})