If a locale is requested for which no locale data is available, an
`UnknownLocaleError` is raised:
- >>> Locale.parse('en_DE')
+ >>> Locale.parse('en_XX')
Traceback (most recent call last):
...
- UnknownLocaleError: unknown locale 'en_DE'
+ UnknownLocaleError: unknown locale 'en_XX'
For more information see :rfc:`3066`.
"""
script_name = property(get_script_name, doc="""\
The localized script name of the locale if available.
- >>> Locale('ms', 'SG', script='Latn').script_name
- u'Latin'
+ >>> Locale('sr', 'ME', script='Latn').script_name
+ u'latinica'
""")
@property
>>> format_datetime(dt, 'full', tzinfo=get_timezone('Europe/Paris'),
... locale='fr_FR')
- u'dimanche 1 avril 2007 17:30:00 heure d\u2019\xe9t\xe9 d\u2019Europe centrale'
+ u'dimanche 1 avril 2007 \xe0 17:30:00 heure d\u2019\xe9t\xe9 d\u2019Europe centrale'
>>> format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
... tzinfo=get_timezone('US/Eastern'), locale='en')
u'2007.04.01 AD at 11:30:00 EDT'
The format parameter controls how compact or wide the presentation is:
>>> format_timedelta(timedelta(hours=3), format='short', locale='en')
- u'3 hrs'
+ u'3 hr'
>>> format_timedelta(timedelta(hours=3), format='narrow', locale='en')
u'3h'
>>> format_currency(1099.98, 'USD', locale='en_US')
u'$1,099.98'
>>> format_currency(1099.98, 'USD', locale='es_CO')
- u'US$1.099,98'
+ u'US$\\xa01.099,98'
>>> format_currency(1099.98, 'EUR', locale='de_DE')
u'1.099,98\\xa0\\u20ac'
import shutil
import hashlib
import zipfile
-import urllib
import subprocess
try:
from urllib.request import urlretrieve
from urllib import urlretrieve
-URL = 'http://unicode.org/Public/cldr/26/core.zip'
-FILENAME = 'core-26.zip'
-FILESUM = '46220170238b092685fd24221f895e3d'
+URL = 'http://unicode.org/Public/cldr/28/core.zip'
+FILENAME = 'core-28.zip'
+FILESUM = 'bc545b4c831e1987ea931b04094d7b9fc59ec3d8'
BLKSIZE = 131072
if not os.path.isfile(filename):
log('Local copy \'%s\' not found', filename)
return False
- h = hashlib.md5()
+ h = hashlib.sha1()
with open(filename, 'rb') as f:
while 1:
blk = f.read(BLKSIZE)
def test_get_plural_falls_back_to_default():
- assert plurals.get_plural('aa') == (2, '(n != 1)')
+ assert plurals.get_plural('ii') == (2, '(n != 1)')
def test_plural_tuple_attributes():
self.assertEqual('0 seconds', string)
string = dates.format_timedelta(timedelta(seconds=0), locale='en',
format='short')
- self.assertEqual('0 secs', string)
+ self.assertEqual('0 sec', string)
string = dates.format_timedelta(timedelta(seconds=0),
granularity='hour', locale='en')
self.assertEqual('0 hours', string)
string = dates.format_timedelta(timedelta(seconds=0),
granularity='hour', locale='en',
format='short')
- self.assertEqual('0 hrs', string)
+ self.assertEqual('0 hr', string)
def test_small_value_with_granularity(self):
string = dates.format_timedelta(timedelta(seconds=42),
full = dates.format_datetime(dt, 'full', tzinfo=timezone('Europe/Paris'),
locale='fr_FR')
- assert full == (u'dimanche 1 avril 2007 17:30:00 heure '
+ assert full == (u'dimanche 1 avril 2007 à 17:30:00 heure '
u'd\u2019\xe9t\xe9 d\u2019Europe centrale')
custom = dates.format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
tzinfo=timezone('US/Eastern'), locale='en')
assert (numbers.format_currency(1099.98, 'USD', locale='en_US')
== u'$1,099.98')
assert (numbers.format_currency(1099.98, 'USD', locale='es_CO')
- == u'US$1.099,98')
+ == u'US$\xa01.099,98')
assert (numbers.format_currency(1099.98, 'EUR', locale='de_DE')
== u'1.099,98\xa0\u20ac')
assert (numbers.format_currency(1099.98, 'EUR', u'\xa4\xa4 #,##0.00',
def test_locales_with_no_plural_rules_have_default():
from babel import Locale
- aa_plural = Locale.parse('aa').plural_form
- assert aa_plural(1) == 'other'
- assert aa_plural(2) == 'other'
- assert aa_plural(15) == 'other'
+ pf = Locale.parse('ii').plural_form
+ assert pf(1) == 'other'
+ assert pf(2) == 'other'
+ assert pf(15) == 'other'
WELL_FORMED_TOKEN_TESTS = (