本文整理汇总了Python中nagare.i18n.set_locale函数的典型用法代码示例。如果您正苦于以下问题:Python set_locale函数的具体用法?Python set_locale怎么用?Python set_locale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_locale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_era_names
def test_get_era_names(self):
i18n.set_locale(i18n.Locale('en', 'US'))
self.assertEqual(i18n.get_era_names(), {0: u'Before Christ', 1: u'Anno Domini'})
self.assertEqual(i18n.get_era_names(width='wide'), {0: u'Before Christ', 1: u'Anno Domini'})
self.assertEqual(i18n.get_era_names(width='abbreviated'), {0: u'BC', 1: u'AD'})
self.assertEqual(i18n.get_era_names(width='narrow'), {0: u'B', 1: u'A'})
示例2: test_format_time_time_with_format
def test_format_time_time_with_format(self):
i18n.set_locale(i18n.Locale('en', 'US', timezone='Pacific/Pitcairn'))
t = datetime.time(15, 30)
self.assertEqual(i18n.format_time(t, format="hh 'o''clock' a, zzzz"), "03 o'clock PM, Pitcairn Time")
t = datetime.time(15, 30, tzinfo=pytz.timezone('Africa/Niamey'))
self.assertEqual(i18n.format_time(t, format="hh 'o''clock' a, zzzz"), "03 o'clock PM, Pitcairn Time")
示例3: test_format_datetime_with_format
def test_format_datetime_with_format(self):
i18n.set_locale(i18n.Locale('en', 'US', timezone='Pacific/Pitcairn'))
d = datetime.datetime(2007, 4, 1, 15, 30)
self.assertEqual(i18n.format_datetime(d, format="yyyy.MM.dd G 'at' HH:mm:ss zzz"), '2007.04.01 AD at 15:30:00 -0800')
tz = pytz.timezone('Africa/Niamey')
d = tz.localize(datetime.datetime(2007, 4, 1, 15, 30))
self.assertEqual(i18n.format_datetime(d, format="yyyy.MM.dd G 'at' HH:mm:ss zzz"), '2007.04.01 AD at 06:30:00 -0800')
示例4: test_format_time_datetime_with_format
def test_format_time_datetime_with_format(self):
i18n.set_locale(i18n.Locale('en', 'US', timezone='Pacific/Pitcairn'))
d = datetime.datetime(2007, 4, 1, 15, 30)
self.assertEqual(i18n.format_time(d, format="hh 'o''clock' a, zzzz"), u"03 o'clock PM, Pitcairn Time")
tz = pytz.timezone('Africa/Niamey')
d = tz.localize(datetime.datetime(2007, 4, 1, 15, 30))
self.assertEqual(i18n.format_time(d, format="hh 'o''clock' a, zzzz"), u"06 o'clock AM, Pitcairn Time")
示例5: test_format_time_datetime_fr3
def test_format_time_datetime_fr3(self):
i18n.set_locale(i18n.Locale('fr', 'FR', timezone='Africa/Niamey', default_timezone=pytz.UTC))
d = datetime.datetime(2007, 4, 1, 15, 30)
self.assertEqual(i18n.format_time(d, format='full'), u'16:30:00 heure normale d’Afrique de l’Ouest')
self.assertEqual(i18n.format_time(d, format='long'), '16:30:00 +0100')
self.assertEqual(i18n.format_time(d, format='medium'), '16:30:00')
self.assertEqual(i18n.format_time(d), '16:30:00')
self.assertEqual(i18n.format_time(d, format='short'), '16:30')
示例6: test_format_time_datetime_fr1
def test_format_time_datetime_fr1(self):
i18n.set_locale(i18n.Locale('fr', 'FR'))
d = datetime.datetime(2007, 4, 1, 15, 30)
self.assertEqual(i18n.format_time(d, format='full'), '15:30:00 UTC+00:00')
self.assertEqual(i18n.format_time(d, format='long'), '15:30:00 +0000')
self.assertEqual(i18n.format_time(d, format='medium'), '15:30:00')
self.assertEqual(i18n.format_time(d), '15:30:00')
self.assertEqual(i18n.format_time(d, format='short'), '15:30')
示例7: set_locale
def set_locale(self, locale):
"""Set the locale of the request scope
In:
- ``locale`` -- the locale
"""
if locale.dirname is None:
locale.dirname = os.path.join(self.data_path, 'locale')
i18n.set_locale(locale)
示例8: set_locale
def set_locale(self, locale):
"""Set the locale of the request scope
In:
- ``locale`` -- the locale
"""
if not locale.has_translation_directory():
locale.add_translation_directory(os.path.join(self.data_path, 'locale'))
i18n.set_locale(locale)
示例9: test_format_time_time_en
def test_format_time_time_en(self):
i18n.set_locale(i18n.Locale('en', 'US', timezone='Pacific/Pitcairn'))
t = datetime.time(15, 30)
self.assertEqual(i18n.format_time(t, format='full'), '3:30:00 PM Pitcairn Time')
self.assertEqual(i18n.format_time(t, format='long'), '3:30:00 PM -0800')
self.assertEqual(i18n.format_time(t, format='medium'), '3:30:00 PM')
self.assertEqual(i18n.format_time(t), '3:30:00 PM')
self.assertEqual(i18n.format_time(t, format='short'), '3:30 PM')
示例10: test_format_time_time_fr1
def test_format_time_time_fr1(self):
i18n.set_locale(i18n.Locale('fr', 'FR'))
t = datetime.time(15, 30)
self.assertEqual(i18n.format_time(t, format='full'), '15:30:00 UTC+00:00')
self.assertEqual(i18n.format_time(t, format='long'), '15:30:00 +0000')
self.assertEqual(i18n.format_time(t, format='medium'), '15:30:00')
self.assertEqual(i18n.format_time(t), '15:30:00')
self.assertEqual(i18n.format_time(t, format='short'), '15:30')
示例11: test_format_time_time_fr4
def test_format_time_time_fr4(self):
i18n.set_locale(i18n.Locale('fr', 'FR', timezone='Africa/Niamey'))
t = datetime.time(15, 30, tzinfo=pytz.timezone('Pacific/Pitcairn'))
self.assertEqual(i18n.format_time(t, format='full'), u'15:30:00 heure normale d’Afrique de l’Ouest')
self.assertEqual(i18n.format_time(t, format='long'), '15:30:00 +0100')
self.assertEqual(i18n.format_time(t, format='medium'), '15:30:00')
self.assertEqual(i18n.format_time(t), '15:30:00')
self.assertEqual(i18n.format_time(t, format='short'), '15:30')
示例12: test_format_time_time_fr3
def test_format_time_time_fr3(self):
i18n.set_locale(i18n.Locale('fr', 'FR'))
t = datetime.time(15, 30, tzinfo=pytz.timezone('Pacific/Pitcairn'))
self.assertEqual(i18n.format_time(t, format='full'), '15:30:00 UTC+00:00')
self.assertEqual(i18n.format_time(t, format='long'), '15:30:00 +0000')
self.assertEqual(i18n.format_time(t, format='medium'), '15:30:00')
self.assertEqual(i18n.format_time(t), '15:30:00')
self.assertEqual(i18n.format_time(t, format='short'), '15:30')
示例13: test_parse_date_en
def test_parse_date_en(self):
i18n.set_locale(i18n.Locale('en', 'US'))
d = i18n.parse_date('4/1/04')
self.assertIsInstance(d, datetime.date)
self.assertEqual((d.year, d.month, d.day), (2004, 4, 1))
d = i18n.parse_date('4/1/2004')
self.assertIsInstance(d, datetime.date)
self.assertEqual((d.year, d.month, d.day), (2004, 4, 1))
示例14: test_format_datetime
def test_format_datetime(self):
i18n.set_locale(i18n.Locale('fr', 'FR', timezone='Africa/Niamey'))
tz = pytz.timezone('Pacific/Pitcairn')
d = tz.localize(datetime.datetime(2007, 4, 1, 15, 30))
self.assertEqual(i18n.format_datetime(d, format='full'), u'lundi 2 avril 2007 à 00:30:00 heure normale d’Afrique de l’Ouest')
self.assertEqual(i18n.format_datetime(d, format='long'), u'2 avril 2007 à 00:30:00 +0100')
self.assertEqual(i18n.format_datetime(d, format='medium'), u'2 avr. 2007 à 00:30:00')
self.assertEqual(i18n.format_datetime(d), u'2 avr. 2007 à 00:30:00')
self.assertEqual(i18n.format_datetime(d, format='short'), '02/04/2007 00:30')
示例15: test_format_time_datetime_fr4
def test_format_time_datetime_fr4(self):
i18n.set_locale(i18n.Locale('fr', 'FR'))
tz = pytz.timezone('Pacific/Pitcairn')
d = tz.localize(datetime.datetime(2007, 4, 1, 15, 30))
self.assertEqual(i18n.format_time(d, format='full'), '23:30:00 UTC+00:00')
self.assertEqual(i18n.format_time(d, format='long'), '23:30:00 +0000')
self.assertEqual(i18n.format_time(d, format='medium'), '23:30:00')
self.assertEqual(i18n.format_time(d), '23:30:00')
self.assertEqual(i18n.format_time(d, format='short'), '23:30')