Rev 5884: Cleanup some PEP8 issues and move test code in test module, test_multiline still failing. in file:///home/vila/src/bzr/reviews/i18n-mod/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri May 27 05:08:22 UTC 2011
At file:///home/vila/src/bzr/reviews/i18n-mod/
------------------------------------------------------------
revno: 5884
revision-id: v.ladeuil+lp at free.fr-20110527050822-wk04ihv0f1ta419z
parent: songofacandy at gmail.com-20110525110655-b4k196m77zx7ovme
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: i18n-mod
timestamp: Fri 2011-05-27 07:08:22 +0200
message:
Cleanup some PEP8 issues and move test code in test module, test_multiline still failing.
-------------- next part --------------
=== modified file 'bzrlib/i18n.py'
--- a/bzrlib/i18n.py 2011-05-25 11:05:39 +0000
+++ b/bzrlib/i18n.py 2011-05-27 05:08:22 +0000
@@ -26,28 +26,35 @@
import os
import sys
-_translation = _null_translation = _gettext.NullTranslations()
-_installed_language = None
+_translation = _gettext.NullTranslations()
def gettext(message):
"""Translate message.
- Returns translated message as unicode."""
+
+ :returns: translated message as unicode.
+ """
return _translation.ugettext(message)
+
def ngettext(s, p, n):
"""Translate message based on `n`.
- Returns translated message as unicode."""
+
+ :returns: translated message as unicode.
+ """
return _translation.ungettext(s, p, n)
+
def N_(msg):
"""Mark message for translation but don't translate it right away."""
return msg
+
def gettext_per_paragraph(message):
"""Translate message per paragraph.
- Returns concatenated translated message as unicode."""
+ :returns: concatenated translated message as unicode.
+ """
paragraphs = message.split(u'\n\n')
ugettext = _translation.ugettext
# Be careful not to translate the empty string -- it holds the
@@ -56,7 +63,7 @@
def install(lang=None):
- global _translation, _installed_language
+ global _translation
if lang is None:
lang = _get_current_locale()
_translation = _gettext.translation(
@@ -65,9 +72,6 @@
languages=lang.split(':'),
fallback=True)
-def install_zzz():
- global _translation
- _translation = _ZzzTranslations()
def uninstall():
global _translation
@@ -129,20 +133,3 @@
if lang:
return lang
return None
-
-class _ZzzTranslations(object):
- """Special Zzz translation for debugging i18n stuff.
-
- This class can be used to confirm the message is properly translated
- while black box test.
- """
-
- def zzz(self, s):
- return u'zz{{%s}}' % s
-
- def ugettext(self, s):
- return self.zzz(_null_translation.ugettext(s))
-
- def ungettext(self, s, p, n):
- return self.zzz(_null_translation.ungettext(s, p, n))
-
=== modified file 'bzrlib/tests/test_i18n.py'
--- a/bzrlib/tests/test_i18n.py 2011-05-17 01:20:21 +0000
+++ b/bzrlib/tests/test_i18n.py 2011-05-27 05:08:22 +0000
@@ -19,6 +19,26 @@
from bzrlib import i18n, tests
+
+
+class ZzzTranslations(object):
+ """Special Zzz translation for debugging i18n stuff.
+
+ This class can be used to confirm that the message is properly translated
+ during black box tests.
+ """
+ _null_translation = i18n._gettext.NullTranslations()
+
+ def zzz(self, s):
+ return u'zz{{%s}}' % s
+
+ def ugettext(self, s):
+ return self.zzz(self._null_translation.ugettext(s))
+
+ def ungettext(self, s, p, n):
+ return self.zzz(self._null_translation.ungettext(s, p, n))
+
+
class TestZzzTranslation(tests.TestCase):
def _check_exact(self, expected, source):
@@ -26,7 +46,7 @@
self.assertEqual(type(expected), type(source))
def test_translation(self):
- trans = i18n._ZzzTranslations()
+ trans = ZzzTranslations()
t = trans.zzz('msg')
self._check_exact(u'zz{{msg}}', t)
@@ -47,7 +67,7 @@
def setUp(self):
super(TestGetText, self).setUp()
- self.overrideAttr(i18n, '_translation', i18n._ZzzTranslations())
+ self.overrideAttr(i18n, '_translation', ZzzTranslations())
def test_oneline(self):
self.assertEqual(u"zz{{spam ham eggs}}",
More information about the bazaar-commits
mailing list