7
from miro import gtcache
8
from miro.test.framework import MiroTestCase
9
from miro.plat import resources
11
# FIXME this only works on GTK platforms. See #3831
13
# The miro.po/miro.mo file for this are in
14
# resources/testdata/locale/fr/LC_MESSAGES/ .
16
# If you need to add messages:
17
# 1. add new strings to teststring.py
20
# xgettext -k_ -kN_ -o messages.pot teststring.py
22
# 3. merge the differences between messages.pot and miro.po file
23
# 4. translate the new strings in miro.po
26
# msgfmt miro.po -o miro.mo
29
def _make_french(*args, **kwargs):
33
old_lang = os.environ["LANGUAGE"]
36
os.environ["LANGUAGE"] = "fr"
39
gettext.bindtextdomain("miro", resources.path("testdata/locale"))
40
gettext.textdomain("miro")
41
gettext.bind_textdomain_codeset("miro", "UTF-8")
47
del os.environ["LANGUAGE"]
49
os.environ["LANGUAGE"] = old_lang
52
INPUT = "parsed %(countfiles)d files - found %(countvideos)d videos"
53
OUTPUT = u'%(countfiles)d fichiers analys\xe9s - %(countvideos)d vid\xe9os trouv\xe9es'
55
class GettextTest(MiroTestCase):
56
# FIXME - we probably want to test that something is logged instead of
57
# ignoring the logging.
59
MiroTestCase.setUp(self)
60
self.oldlevel = logging.getLogger().level
61
logging.getLogger().setLevel(logging.ERROR)
64
MiroTestCase.tearDown(self)
65
logging.getLogger().setLevel(self.oldlevel)
68
def test_gettext(self):
69
self.assertEqual(gtcache.gettext("OK"), u'Valider')
70
self.assertEqual(gtcache.gettext("Channels"), u'Cha\xeenes')
73
def test_gettext_values(self):
74
# test with no value expansion
75
self.assertEqual(gtcache.gettext(INPUT), OUTPUT)
77
# test with old value expansion
78
self.assertEqual(gtcache.gettext(INPUT) % {"countfiles": 1, "countvideos": 2},
79
OUTPUT % {"countfiles": 1, "countvideos": 2})
81
# test with value expansion done by gtcache.gettext
82
self.assertEqual(gtcache.gettext(INPUT,
83
{"countfiles": 1, "countvideos": 2}),
84
OUTPUT % {"countfiles": 1, "countvideos": 2})
87
def test_gettext_values_failures(self):
88
# try gettext with a bad translation. the string is fine, but
89
# the translated version of the string is missing the d
90
# characters which causes a Python formatting syntax error.
91
input2 = "bad parsed %(countfiles)d files - found %(countvideos)d videos"
93
# first we call gettext on the string by itself--this is fine,
94
# so we should get the translated version of the string.
95
self.assertEqual(gtcache.gettext(input2),
96
u'bad %(countfiles) fichiers analys\xe9s - %(countvideos) vid\xe9os trouv\xe9es')
98
# now we pass in a values dict which will kick up a ValueError
99
# when trying to expand the values. that causes gettext to
100
# return the english form of the string with values expanded.
101
self.assertEqual(gtcache.gettext(input2,
102
{"countfiles": 1, "countvideos": 2}),
103
input2 % {"countfiles": 1, "countvideos": 2})
106
def test_ngettext(self):
107
# french uses singular for 0, 1 and plural for everything else.
108
self.assertEqual(gtcache.ngettext("%(count)d video found",
109
"%(count)d videos found", 0),
110
u'%(count)d vid\xe9o trouv\xe9e')
112
self.assertEqual(gtcache.ngettext("%(count)d video found",
113
"%(count)d videos found", 1),
114
u'%(count)d vid\xe9o trouv\xe9e')
116
self.assertEqual(gtcache.ngettext("%(count)d video found",
117
"%(count)d videos found", 2),
118
u'%(count)d vid\xe9os trouv\xe9es')
121
def test_ngettext_values(self):
122
# try the bad translation with no values
123
self.assertEqual(gtcache.ngettext("bad %(count)d video found",
124
"bad %(count)d videos found", 0),
125
u'bad %(count) vid\xe9o trouv\xe9e')
127
# try the bad translation with values
128
self.assertEqual(gtcache.ngettext("bad %(count)d video found",
129
"bad %(count)d videos found", 0,
131
u'bad 0 videos found')
133
self.assertEqual(gtcache.ngettext("bad %(count)d video found",
134
"bad %(count)d videos found", 1,
136
u'bad 1 video found')
138
self.assertEqual(gtcache.ngettext("bad %(count)d video found",
139
"bad %(count)d videos found", 2,
141
u'bad 2 videos found')