Commit bded4d3b authored by Georg Brandl's avatar Georg Brandl

Make gettext Unicode interface consistent and clean up the docs.

parent 6a9475f6
This diff is collapsed.
...@@ -304,26 +304,16 @@ class GNUTranslations(NullTranslations): ...@@ -304,26 +304,16 @@ class GNUTranslations(NullTranslations):
# cause no problems since us-ascii should always be a subset of # cause no problems since us-ascii should always be a subset of
# the charset encoding. We may want to fall back to 8-bit msgids # the charset encoding. We may want to fall back to 8-bit msgids
# if the Unicode conversion fails. # if the Unicode conversion fails.
charset = self._charset or 'ascii'
if b'\x00' in msg: if b'\x00' in msg:
# Plural forms # Plural forms
msgid1, msgid2 = msg.split(b'\x00') msgid1, msgid2 = msg.split(b'\x00')
tmsg = tmsg.split(b'\x00') tmsg = tmsg.split(b'\x00')
if self._charset: msgid1 = str(msgid1, charset)
msgid1 = str(msgid1, self._charset) for i, x in enumerate(tmsg):
tmsg = [str(x, self._charset) for x in tmsg] catalog[(msgid1, i)] = str(x, charset)
else: else:
msgid1 = str(msgid1) catalog[str(msg, charset)] = str(tmsg, charset)
tmsg = [str(x) for x in tmsg]
for i in range(len(tmsg)):
catalog[(msgid1, i)] = tmsg[i]
else:
if self._charset:
msg = str(msg, self._charset)
tmsg = str(tmsg, self._charset)
else:
msg = str(msg)
tmsg = str(tmsg)
catalog[msg] = tmsg
# advance to next entry in the seek tables # advance to next entry in the seek tables
masteridx += 8 masteridx += 8
transidx += 8 transidx += 8
...@@ -359,7 +349,7 @@ class GNUTranslations(NullTranslations): ...@@ -359,7 +349,7 @@ class GNUTranslations(NullTranslations):
if tmsg is missing: if tmsg is missing:
if self._fallback: if self._fallback:
return self._fallback.gettext(message) return self._fallback.gettext(message)
return str(message) return message
return tmsg return tmsg
def ngettext(self, msgid1, msgid2, n): def ngettext(self, msgid1, msgid2, n):
...@@ -369,9 +359,9 @@ class GNUTranslations(NullTranslations): ...@@ -369,9 +359,9 @@ class GNUTranslations(NullTranslations):
if self._fallback: if self._fallback:
return self._fallback.ngettext(msgid1, msgid2, n) return self._fallback.ngettext(msgid1, msgid2, n)
if n == 1: if n == 1:
tmsg = str(msgid1) tmsg = msgid1
else: else:
tmsg = str(msgid2) tmsg = msgid2
return tmsg return tmsg
......
...@@ -47,8 +47,8 @@ Library ...@@ -47,8 +47,8 @@ Library
code of every single module of the standard library, including invalid files code of every single module of the standard library, including invalid files
used in the test suite. used in the test suite.
- All the u* variant functions and methods in gettext have been renamed to their - The gettext library now consistently uses Unicode strings for message ids
none u* siblings. and message strings, and ``ugettext()`` and the like don't exist anymore.
- The traceback module has been expanded to handle chained exceptions. - The traceback module has been expanded to handle chained exceptions.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment