]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
More gettext fixes
authorArmin Ronacher <armin.ronacher@active-4.com>
Sat, 6 Jul 2013 20:18:47 +0000 (22:18 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sat, 6 Jul 2013 20:18:47 +0000 (22:18 +0200)
babel/messages/frontend.py
babel/support.py
tests/messages/test_mofile.py
tests/messages/test_pofile.py

index 377851131cb8cb56d211158f9228c775bb563e11..59c4b55d97fa8008423a675367aa5cd751124e44 100755 (executable)
@@ -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,
index fb6d3ad1d17005b8927516831f6de0a1be3dfd1c..5c76cd68004b2a6f122d791b036e1b768aafa65e 100644 (file)
@@ -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
-
index c381cec18080c3246337fb95ebdbca61d3386fc3..200704eb69ed9f831e8f56c618fb2e3e592cbc99 100644 (file)
 # 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))
index 59b8a24fd99bbcba888d5fa835b06ea3d467d097..3bb055714ff5668c04eaeac8a4175e618486b953 100644 (file)
@@ -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 <EMAIL@ADDRESS>, 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'''\