示例#1
0
 def test_funky_encoding(self):
     translation.add_domain('foo', self._localedir('locale1'))
     translation.set_language(('ja_JP.SJIS',))
     self.assertEqual(translation.gettext('test'), '\x82\x9f\x83@\xea\x9f\xea\xa2')
     # Default locale is normally us-ascii, can't convert shift-jis to ASCII.
     self.assertRaises(UnicodeEncodeError, translation.lgettext, 'test')
     os.environ['LANG'] = 'ja_JP.SJIS'
     try:
         self.assertEqual(translation.lgettext('test'), '\x82\x9f\x83@\xea\x9f\xea\xa2')
         os.environ['LANG'] = 'ja_JP.UTF-8'
         self.assertEqual(translation.lgettext('test'), '\xe3\x81\x81\xe3\x82\xa1\xe5\xa0\xaf\xe7\x91\xa4')
     finally:
         del os.environ['LANG']
     self.assertEqual(translation.ugettext('test'), u'\u3041\u30a1\u582f\u7464')
示例#2
0
 def test_funky_encoding(self):
     translation.add_domain('foo', self._localedir('locale1'))
     translation.set_language(('ja_JP.SJIS', ))
     self.assertEqual(translation.gettext('test'),
                      '\x82\x9f\x83@\xea\x9f\xea\xa2')
     # Default locale is normally us-ascii, can't convert shift-jis to ASCII.
     self.assertRaises(UnicodeEncodeError, translation.lgettext, 'test')
     os.environ['LANG'] = 'ja_JP.SJIS'
     try:
         self.assertEqual(translation.lgettext('test'),
                          '\x82\x9f\x83@\xea\x9f\xea\xa2')
         os.environ['LANG'] = 'ja_JP.UTF-8'
         self.assertEqual(
             translation.lgettext('test'),
             '\xe3\x81\x81\xe3\x82\xa1\xe5\xa0\xaf\xe7\x91\xa4')
     finally:
         del os.environ['LANG']
     self.assertEqual(translation.ugettext('test'),
                      u'\u3041\u30a1\u582f\u7464')
示例#3
0
 def test_preferred_locale(self):
     translation.add_domain('foo', self._localedir('locale1'))
     for lang, matches in self.foo_expected.items():
         translation.set_language((lang,))
         for source, trans in matches.items():
             try:
                 unicode(trans, 'US-ASCII')
             except UnicodeDecodeError:
                 self.assertRaises(UnicodeEncodeError, translation.lgettext, source)
                 l = translation.lgettext_lazy(source)
                 self.assertRaises(UnicodeEncodeError, lambda: str(l))
                 self.assertRaises(UnicodeEncodeError, lambda: unicode(l))
             else:
                 self.assertEqual(translation.lgettext(source), trans)
                 self.assertEqual(translation.lgettext_lazy(source), trans)
             os.environ['LANG'] = 'es_ES.UTF-8'
             try:
                 self.assertEqual(translation.lgettext(source), trans)
                 self.assertEqual(translation.lgettext_lazy(source), trans)
             finally:
                 del os.environ['LANG']
示例#4
0
 def test_preferred_locale(self):
     translation.add_domain('foo', self._localedir('locale1'))
     for lang, matches in self.foo_expected.items():
         translation.set_language((lang, ))
         for source, trans in matches.items():
             try:
                 unicode(trans, 'US-ASCII')
             except UnicodeDecodeError:
                 self.assertRaises(UnicodeEncodeError, translation.lgettext,
                                   source)
                 l = translation.lgettext_lazy(source)
                 self.assertRaises(UnicodeEncodeError, lambda: str(l))
                 self.assertRaises(UnicodeEncodeError, lambda: unicode(l))
             else:
                 self.assertEqual(translation.lgettext(source), trans)
                 self.assertEqual(translation.lgettext_lazy(source), trans)
             os.environ['LANG'] = 'es_ES.UTF-8'
             try:
                 self.assertEqual(translation.lgettext(source), trans)
                 self.assertEqual(translation.lgettext_lazy(source), trans)
             finally:
                 del os.environ['LANG']