51
49
trans = ZzzTranslations()
53
51
t = trans.zzz('msg')
54
self._check_exact(u'zz\xe5{{msg}}', t)
52
self._check_exact(u'zz{{msg}}', t)
56
54
t = trans.ugettext('msg')
57
self._check_exact(u'zz\xe5{{msg}}', t)
55
self._check_exact(u'zz{{msg}}', t)
59
57
t = trans.ungettext('msg1', 'msg2', 0)
60
self._check_exact(u'zz\xe5{{msg2}}', t)
58
self._check_exact(u'zz{{msg2}}', t)
61
59
t = trans.ungettext('msg1', 'msg2', 2)
62
self._check_exact(u'zz\xe5{{msg2}}', t)
60
self._check_exact(u'zz{{msg2}}', t)
64
62
t = trans.ungettext('msg1', 'msg2', 1)
65
self._check_exact(u'zz\xe5{{msg1}}', t)
63
self._check_exact(u'zz{{msg1}}', t)
68
66
class TestGetText(tests.TestCase):
71
69
super(TestGetText, self).setUp()
72
self.overrideAttr(i18n, '_translations', ZzzTranslations())
70
self.overrideAttr(i18n, '_translation', ZzzTranslations())
74
72
def test_oneline(self):
75
self.assertEqual(u"zz\xe5{{spam ham eggs}}",
73
self.assertEqual(u"zz{{spam ham eggs}}",
76
74
i18n.gettext("spam ham eggs"))
78
76
def test_multiline(self):
79
self.assertEqual(u"zz\xe5{{spam\nham\n\neggs\n}}",
77
self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
80
78
i18n.gettext("spam\nham\n\neggs\n"))
86
84
super(TestGetTextPerParagraph, self).setUp()
87
self.overrideAttr(i18n, '_translations', ZzzTranslations())
85
self.overrideAttr(i18n, '_translation', ZzzTranslations())
89
87
def test_oneline(self):
90
self.assertEqual(u"zz\xe5{{spam ham eggs}}",
88
self.assertEqual(u"zz{{spam ham eggs}}",
91
89
i18n.gettext_per_paragraph("spam ham eggs"))
93
91
def test_multiline(self):
94
self.assertEqual(u"zz\xe5{{spam\nham}}\n\nzz\xe5{{eggs\n}}",
92
self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
95
93
i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))
98
class TestInstall(tests.TestCase):
101
super(TestInstall, self).setUp()
102
# Restore a proper env to test translation installation
103
self.overrideAttr(i18n, '_translations', None)
105
def test_custom_languages(self):
106
i18n.install('nl:fy')
107
# Whether we found a valid tranlsation or not doesn't matter, we got
108
# one and _translations is not None anymore.
109
self.assertIsInstance(i18n._translations,
110
i18n._gettext.NullTranslations)
112
def test_no_env_variables(self):
113
self.overrideEnv('LANGUAGE', None)
114
self.overrideEnv('LC_ALL', None)
115
self.overrideEnv('LC_MESSAGES', None)
116
self.overrideEnv('LANG', None)
118
# Whether we found a valid tranlsation or not doesn't matter, we got
119
# one and _translations is not None anymore.
120
self.assertIsInstance(i18n._translations,
121
i18n._gettext.NullTranslations)
123
def test_disable_i18n(self):
126
# It's disabled, you can't install anything and we fallback to null
127
self.assertIsInstance(i18n._translations,
128
i18n._gettext.NullTranslations)
131
class TestTranslate(tests.TestCaseWithTransport):
134
super(TestTranslate, self).setUp()
135
self.overrideAttr(i18n, '_translations', ZzzTranslations())
137
def test_error_message_translation(self):
138
"""do errors get translated?"""
140
tree = self.make_branch_and_tree('.')
142
workingtree.WorkingTree.open('./foo')
143
except errors.NotBranchError,e:
145
self.assertContainsRe(err,
146
u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))
148
def test_topic_help_translation(self):
149
"""does topic help get translated?"""
150
from bzrlib import help
151
from StringIO import StringIO
153
help.help("authentication", out)
154
self.assertContainsRe(out.getvalue(), "zz\xe5{{Authentication Settings")