本文整理汇总了Python中nxdrive.wui.translator.Translator.locale方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.locale方法的具体用法?Python Translator.locale怎么用?Python Translator.locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nxdrive.wui.translator.Translator
的用法示例。
在下文中一共展示了Translator.locale方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLoadFile
# 需要导入模块: from nxdrive.wui.translator import Translator [as 别名]
# 或者: from nxdrive.wui.translator.Translator import locale [as 别名]
def testLoadFile(self):
manager = MockManager()
Translator(manager, self.getFolder('i18n.js'))
# Verify the call to save
self.assertTrue(manager.called)
self.assertEqual("en", Translator.locale())
manager.called = False
# Change to an existing language
Translator.set("fr")
self.assertTrue(manager.called)
self.assertEqual("fr", Translator.locale())
# Test unkown key
self.assertEqual("BOUZOUF", Translator.get("BOUZOUF"))
# Test fallback
self.assertEqual("Fallback", Translator.get("FALLBACK"))
manager.called = False
# Try to switch to bad language
self.assertRaises(Exception, Translator.set, "de")
self.assertEqual("fr", Translator.locale())
self.assertFalse(manager.called)
self.assertRaises(Exception, Translator.set, "es")
self.assertEqual("fr", Translator.locale())
# Nothing should be saved
self.assertFalse(manager.called)
# Go back to an existing one
Translator.set("en")
self.assertTrue(manager.called)
self.assertEqual("en", Translator.locale())
self.assertEqual("BOUZOUF", Translator.get("BOUZOUF"))
示例2: testLoadExistingLanguage
# 需要导入模块: from nxdrive.wui.translator import Translator [as 别名]
# 或者: from nxdrive.wui.translator.Translator import locale [as 别名]
def testLoadExistingLanguage(self):
Translator(MockManager(), self.getFolder('i18n.js'), "fr")
# Should not fallback on en
self.assertEqual("fr", Translator.locale())
# Test the key fallback
self.assertEqual("Fallback", Translator.get("FALLBACK"))
self.assertEqual(u"Fran\xe7ais", Translator.get("LANGUAGE"))
self.assertEqual("BOUZOUF", Translator.get("BOUZOUF"))
示例3: locale
# 需要导入模块: from nxdrive.wui.translator import Translator [as 别名]
# 或者: from nxdrive.wui.translator.Translator import locale [as 别名]
def locale(self):
try:
return Translator.locale()
except Exception as e:
log.exception(e)
return ""
示例4: testLoadNonExistingLanguage
# 需要导入模块: from nxdrive.wui.translator import Translator [as 别名]
# 或者: from nxdrive.wui.translator.Translator import locale [as 别名]
def testLoadNonExistingLanguage(self):
Translator(MockManager(), self.getFolder('i18n.js'), "es")
# Should fallback on en
self.assertEqual("en", Translator.locale())
示例5: test_load_bad_language
# 需要导入模块: from nxdrive.wui.translator import Translator [as 别名]
# 或者: from nxdrive.wui.translator.Translator import locale [as 别名]
def test_load_bad_language(self):
Translator(MockManager(), get_folder('i18n.js'), "zzzzzz")
# Should fallback on en
self.assertEqual("en", Translator.locale())
示例6: locale
# 需要导入模块: from nxdrive.wui.translator import Translator [as 别名]
# 或者: from nxdrive.wui.translator.Translator import locale [as 别名]
def locale(self):
try:
return Translator.locale()
except RuntimeError as e:
log.exception(repr(e))
return ''