52
47
trans = ZzzTranslations()
54
49
t = trans.zzz('msg')
55
self._check_exact(u'zz\xe5{{msg}}', t)
50
self._check_exact(u'zz{{msg}}', t)
57
52
t = trans.ugettext('msg')
58
self._check_exact(u'zz\xe5{{msg}}', t)
53
self._check_exact(u'zz{{msg}}', t)
60
55
t = trans.ungettext('msg1', 'msg2', 0)
61
self._check_exact(u'zz\xe5{{msg2}}', t)
56
self._check_exact(u'zz{{msg2}}', t)
62
57
t = trans.ungettext('msg1', 'msg2', 2)
63
self._check_exact(u'zz\xe5{{msg2}}', t)
58
self._check_exact(u'zz{{msg2}}', t)
65
60
t = trans.ungettext('msg1', 'msg2', 1)
66
self._check_exact(u'zz\xe5{{msg1}}', t)
61
self._check_exact(u'zz{{msg1}}', t)
69
64
class TestGetText(tests.TestCase):
73
68
self.overrideAttr(i18n, '_translations', ZzzTranslations())
75
70
def test_oneline(self):
76
self.assertEqual(u"zz\xe5{{spam ham eggs}}",
71
self.assertEqual(u"zz{{spam ham eggs}}",
77
72
i18n.gettext("spam ham eggs"))
79
74
def test_multiline(self):
80
self.assertEqual(u"zz\xe5{{spam\nham\n\neggs\n}}",
75
self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
81
76
i18n.gettext("spam\nham\n\neggs\n"))
88
83
self.overrideAttr(i18n, '_translations', ZzzTranslations())
90
85
def test_oneline(self):
91
self.assertEqual(u"zz\xe5{{spam ham eggs}}",
86
self.assertEqual(u"zz{{spam ham eggs}}",
92
87
i18n.gettext_per_paragraph("spam ham eggs"))
94
89
def test_multiline(self):
95
self.assertEqual(u"zz\xe5{{spam\nham}}\n\nzz\xe5{{eggs\n}}",
90
self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
96
91
i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))
99
94
class TestInstall(tests.TestCase):
102
super(TestInstall, self).setUp()
103
# Restore a proper env to test translation installation
104
self.overrideAttr(i18n, '_translations', None)
106
96
def test_custom_languages(self):
97
self.addCleanup(i18n.install)
107
98
i18n.install('nl:fy')
108
# Whether we found a valid tranlsation or not doesn't matter, we got
109
# one and _translations is not None anymore.
110
self.assertIsInstance(i18n._translations,
111
i18n._gettext.NullTranslations)
113
100
def test_no_env_variables(self):
101
self.addCleanup(i18n.install)
114
102
self.overrideEnv('LANGUAGE', None)
115
103
self.overrideEnv('LC_ALL', None)
116
104
self.overrideEnv('LC_MESSAGES', None)
117
105
self.overrideEnv('LANG', None)
119
# Whether we found a valid tranlsation or not doesn't matter, we got
120
# one and _translations is not None anymore.
121
self.assertIsInstance(i18n._translations,
122
i18n._gettext.NullTranslations)
124
def test_disable_i18n(self):
127
# It's disabled, you can't install anything and we fallback to null
128
self.assertIsInstance(i18n._translations,
129
i18n._gettext.NullTranslations)
132
class TestTranslate(tests.TestCaseWithTransport):
135
super(TestTranslate, self).setUp()
136
self.overrideAttr(i18n, '_translations', ZzzTranslations())
138
def test_error_message_translation(self):
139
"""do errors get translated?"""
141
tree = self.make_branch_and_tree('.')
143
workingtree.WorkingTree.open('./foo')
144
except errors.NotBranchError,e:
146
self.assertContainsRe(err,
147
u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))
149
def test_topic_help_translation(self):
150
"""does topic help get translated?"""
151
from bzrlib import help
152
from StringIO import StringIO
154
help.help("authentication", out)
155
self.assertContainsRe(out.getvalue(), "zz\xe5{{Authentication Settings")
158
class LoadPluginTranslations(tests.TestCase):
160
def test_does_not_exist(self):
161
translation = i18n.load_plugin_translations("doesnotexist")
162
self.assertEquals("foo", translation.gettext("foo"))