Skip to content

Commit

Permalink
In version 3.7.2 msgids and default values where forced to be unicode…
Browse files Browse the repository at this point in the history
…s. 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.
  • Loading branch information
Michael Howitz committed May 14, 2012
1 parent cf2acf9 commit 3788bd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions src/zope/app/locales/extract.py
Expand Up @@ -97,7 +97,7 @@ class POTEntry(object):
msgstr ""
<BLANKLINE>
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())
Expand All @@ -106,6 +106,16 @@ class POTEntry(object):
msgstr ""
<BLANKLINE>
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 ""
<BLANKLINE>
"""

implements(IPOTEntry)
Expand All @@ -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)):
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit 3788bd8

Please sign in to comment.