From: Armin Ronacher Date: Sat, 6 Jul 2013 20:18:47 +0000 (+0200) Subject: More gettext fixes X-Git-Tag: 1.0~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4f8a4b179fdfebd032aa910bba82c5c5746d0f7;p=thirdparty%2Fbabel.git More gettext fixes --- diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index 37785113..59c4b55d 100755 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -951,6 +951,7 @@ class CommandLineInterface(object): close_output = False try: + print(outfile) write_po(outfile, catalog, width=options.width, no_location=options.no_location, omit_header=options.omit_header, diff --git a/babel/support.py b/babel/support.py index fb6d3ad1..5c76cd68 100644 --- a/babel/support.py +++ b/babel/support.py @@ -17,7 +17,6 @@ in applications. .. note: the code in this module is not used by Babel itself """ -from datetime import date, datetime, timedelta import gettext import locale @@ -26,7 +25,7 @@ from babel.dates import format_date, format_datetime, format_time, \ format_timedelta from babel.numbers import format_number, format_decimal, format_currency, \ format_percent, format_scientific -from babel.util import UTC +from babel._compat import PY2 __all__ = ['Format', 'LazyProxy', 'NullTranslations', 'Translations'] @@ -521,6 +520,12 @@ class NullTranslations(gettext.NullTranslations, object): return self._domains.get(domain, self).lnpgettext(context, singular, plural, num) + if not PY2: + ugettext = gettext.NullTranslations.gettext + ungettext = gettext.NullTranslations.ngettext + upgettext = gettext.NullTranslations.pgettext + upnpgettext = gettext.NullTranslations.npgettext + class Translations(NullTranslations, gettext.GNUTranslations): """An extended translation catalog class.""" @@ -536,6 +541,12 @@ class Translations(NullTranslations, gettext.GNUTranslations): super(Translations, self).__init__(fp=fp) self.domain = domain or self.DEFAULT_DOMAIN + if not PY2: + ugettext = gettext.GNUTranslations.gettext + ungettext = gettext.GNUTranslations.ngettext + upgettext = gettext.GNUTranslations.pgettext + upnpgettext = gettext.GNUTranslations.npgettext + @classmethod def load(cls, dirname=None, locales=None, domain=None): """Load translations from the given directory. @@ -612,4 +623,3 @@ class Translations(NullTranslations, gettext.GNUTranslations): self.files.extend(translations.files) return self - diff --git a/tests/messages/test_mofile.py b/tests/messages/test_mofile.py index c381cec1..200704eb 100644 --- a/tests/messages/test_mofile.py +++ b/tests/messages/test_mofile.py @@ -11,12 +11,12 @@ # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. -import gettext import os import unittest from babel.messages import mofile, Catalog from babel._compat import BytesIO +from babel.util import Translations class ReadMoTestCase(unittest.TestCase): @@ -57,7 +57,7 @@ class WriteMoTestCase(unittest.TestCase): buf = BytesIO() mofile.write_mo(buf, catalog) buf.seek(0) - translations = gettext.GNUTranslations(fp=buf) + translations = Translations(fp=buf) self.assertEqual(u'Voh', translations.ugettext('foo')) assert isinstance(translations.ugettext('foo'), unicode) self.assertEqual(u'Es gibt', translations.ungettext('There is', 'There are', 1)) diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py index 59b8a24f..3bb05571 100644 --- a/tests/messages/test_pofile.py +++ b/tests/messages/test_pofile.py @@ -36,7 +36,7 @@ msgstr "Voh"''') self.assertEqual('mydomain', catalog.domain) def test_applies_specified_encoding_during_read(self): - buf = StringIO(u''' + buf = BytesIO(u''' msgid "" msgstr "" "Project-Id-Version: 3.15\\n" @@ -165,7 +165,7 @@ msgstr "Bahr" self.assertEqual(0, len(catalog.obsolete)) def test_with_context(self): - buf = StringIO(r'''# Some string in the menu + buf = BytesIO(b'''# Some string in the menu #: main.py:1 msgctxt "Menu" msgid "foo" @@ -191,7 +191,7 @@ msgstr "Bahr" out_buf.getvalue() def test_with_context_two(self): - buf = StringIO(r'''msgctxt "Menu" + buf = BytesIO(b'''msgctxt "Menu" msgid "foo" msgstr "Voh" @@ -265,7 +265,7 @@ class WritePoTestCase(unittest.TestCase): catalog.add(u'foo', locations=[('utils.py', 3)]) buf = BytesIO() pofile.write_po(buf, catalog, omit_header=True) - self.assertEqual('''#: main.py:1 utils.py:3 + self.assertEqual(b'''#: main.py:1 utils.py:3 msgid "foo" msgstr ""''', buf.getvalue().strip()) @@ -275,7 +275,7 @@ msgstr ""''', buf.getvalue().strip()) buf = BytesIO() pofile.write_po(buf, catalog, omit_header=False) po_file = buf.getvalue().strip() - assert r'"Content-Type: text/plain; charset=iso-8859-1\n"' in po_file + assert b'"Content-Type: text/plain; charset=iso-8859-1\\n"' in po_file assert u'msgstr "äöü"'.encode('iso-8859-1') in po_file def test_duplicate_comments(self): @@ -340,7 +340,7 @@ msgstr ""''', buf.getvalue().strip()) # AReallyReallyLongNameForAProject project. # FIRST AUTHOR , 2007. # -#, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) +#, fuzzy''', b'\n'.join(buf.getvalue().splitlines()[:7])) def test_wrap_locations_with_hyphens(self): catalog = Catalog() @@ -511,7 +511,7 @@ msgid "foo" msgid_plural "foos" msgstr[0] "Voh" msgstr[1] "Voeh"''' in value - assert value.find('msgid ""') < value.find('msgid "bar"') < value.find('msgid "foo"') + assert value.find(b'msgid ""') < value.find(b'msgid "bar"') < value.find(b'msgid "foo"') def test_silent_location_fallback(self): buf = BytesIO(b'''\