本文整理汇总了Python中__builtin__.gettext方法的典型用法代码示例。如果您正苦于以下问题:Python __builtin__.gettext方法的具体用法?Python __builtin__.gettext怎么用?Python __builtin__.gettext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类__builtin__
的用法示例。
在下文中一共展示了__builtin__.gettext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_the_alternative_interface
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_the_alternative_interface(self):
eq = self.assertEqual
# test the alternative interface
with open(self.mofile, 'rb') as fp:
t = gettext.GNUTranslations(fp)
# Install the translation object
t.install()
eq(_('nudge nudge'), 'wink wink')
# Try unicode return type
t.install(unicode=True)
eq(_('mullusk'), 'bacon')
# Test installation of other methods
import __builtin__
t.install(unicode=True, names=["gettext", "lgettext"])
eq(_, t.ugettext)
eq(__builtin__.gettext, t.ugettext)
eq(lgettext, t.lgettext)
del __builtin__.gettext
del __builtin__.lgettext
示例2: test_cache
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_cache(self):
self.localedir = os.curdir
self.mofile = MOFILE
self.assertEqual(len(gettext._translations), 0)
t = gettext.translation('gettext', self.localedir)
self.assertEqual(len(gettext._translations), 1)
t = gettext.translation('gettext', self.localedir,
class_=DummyGNUTranslations)
self.assertEqual(len(gettext._translations), 2)
self.assertEqual(t.__class__, DummyGNUTranslations)
# Calling it again doesn't add to the cache
t = gettext.translation('gettext', self.localedir,
class_=DummyGNUTranslations)
self.assertEqual(len(gettext._translations), 2)
self.assertEqual(t.__class__, DummyGNUTranslations)
示例3: setUp
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def setUp(self):
if not os.path.isdir(LOCALEDIR):
os.makedirs(LOCALEDIR)
with open(MOFILE, 'wb') as fp:
fp.write(base64.decodestring(GNU_MO_DATA))
with open(UMOFILE, 'wb') as fp:
fp.write(base64.decodestring(UMO_DATA))
with open(MMOFILE, 'wb') as fp:
fp.write(base64.decodestring(MMO_DATA))
self.env = test_support.EnvironmentVarGuard()
self.env['LANGUAGE'] = 'xx'
gettext._translations.clear()
示例4: test_multiline_strings
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_multiline_strings(self):
eq = self.assertEqual
# multiline strings
eq(_('''This module provides internationalization and localization
support for your Python programs by providing an interface to the GNU
gettext message catalog library.'''),
'''Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba
fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH
trggrkg zrffntr pngnybt yvoenel.''')
示例5: test_textdomain
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_textdomain(self):
self.assertEqual(gettext.textdomain(), 'gettext')
示例6: test_plural_forms1
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_plural_forms1(self):
eq = self.assertEqual
x = gettext.ngettext('There is %s file', 'There are %s files', 1)
eq(x, 'Hay %s fichero')
x = gettext.ngettext('There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros')
示例7: test_plural_forms2
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_plural_forms2(self):
eq = self.assertEqual
with open(self.mofile, 'rb') as fp:
t = gettext.GNUTranslations(fp)
x = t.ngettext('There is %s file', 'There are %s files', 1)
eq(x, 'Hay %s fichero')
x = t.ngettext('There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros')
# Examples from http://www.gnu.org/software/gettext/manual/gettext.html
示例8: test_ja
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_ja(self):
eq = self.assertEqual
f = gettext.c2py('0')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
示例9: test_fr
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_fr(self):
eq = self.assertEqual
f = gettext.c2py('n>1')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
示例10: test_lv
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_lv(self):
eq = self.assertEqual
f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "20111111111111111111101111111110111111111011111111101111111110111111111011111111101111111110111111111011111111111111111110111111111011111111101111111110111111111011111111101111111110111111111011111111")
示例11: test_gd
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_gd(self):
eq = self.assertEqual
f = gettext.c2py('n==1 ? 0 : n==2 ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")
示例12: test_gd2
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_gd2(self):
eq = self.assertEqual
# Tests the combination of parentheses and "?:"
f = gettext.c2py('n==1 ? 0 : (n==2 ? 1 : 2)')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")
示例13: test_ro
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_ro(self):
eq = self.assertEqual
f = gettext.c2py('n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "10111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222")
示例14: test_ru
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_ru(self):
eq = self.assertEqual
f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "20111222222222222222201112222220111222222011122222201112222220111222222011122222201112222220111222222011122222222222222220111222222011122222201112222220111222222011122222201112222220111222222011122222")
示例15: test_cs
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import gettext [as 别名]
def test_cs(self):
eq = self.assertEqual
f = gettext.c2py('(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "20111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")