Skip to content

Commit 304ef12

Browse files
authored
Merge pull request #951 from python-babel/cldr-42
Upgrade to CLDR 42
2 parents cf405e2 + d76db13 commit 304ef12

File tree

11 files changed

+54
-42
lines changed

11 files changed

+54
-42
lines changed

babel/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ def time_formats(self) -> localedata.LocaleDataDict:
855855
Babel versions.
856856
857857
>>> Locale('en', 'US').time_formats['short']
858-
<DateTimePattern u'h:mm a'>
858+
<DateTimePattern u'h:mm\u202fa'>
859859
>>> Locale('fr', 'FR').time_formats['long']
860860
<DateTimePattern u'HH:mm:ss z'>
861861
"""
@@ -869,7 +869,7 @@ def datetime_formats(self) -> localedata.LocaleDataDict:
869869
Babel versions.
870870
871871
>>> Locale('en').datetime_formats['full']
872-
u"{1} 'at' {0}"
872+
u'{1}, {0}'
873873
>>> Locale('th').datetime_formats['medium']
874874
u'{1} {0}'
875875
"""

babel/dates.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def get_time_format(format: _PredefinedTimeFormat = 'medium', locale: Locale | s
497497
format.
498498
499499
>>> get_time_format(locale='en_US')
500-
<DateTimePattern u'h:mm:ss a'>
500+
<DateTimePattern u'h:mm:ss\u202fa'>
501501
>>> get_time_format('full', locale='de_DE')
502502
<DateTimePattern u'HH:mm:ss zzzz'>
503503
@@ -580,14 +580,14 @@ def get_timezone_location(
580580
581581
>>> tz = get_timezone('America/St_Johns')
582582
>>> print(get_timezone_location(tz, locale='de_DE'))
583-
Kanada (St. John’s) Zeit
583+
Kanada (St. John’s) (Ortszeit)
584584
>>> print(get_timezone_location(tz, locale='en'))
585585
Canada (St. John’s) Time
586586
>>> print(get_timezone_location(tz, locale='en', return_city=True))
587587
St. John’s
588588
>>> tz = get_timezone('America/Mexico_City')
589589
>>> get_timezone_location(tz, locale='de_DE')
590-
u'Mexiko (Mexiko-Stadt) Zeit'
590+
u'Mexiko (Mexiko-Stadt) (Ortszeit)'
591591
592592
If the timezone is associated with a country that uses only a single
593593
timezone, just the localized country name is returned:
@@ -823,13 +823,13 @@ def format_datetime(
823823
>>> from datetime import datetime
824824
>>> dt = datetime(2007, 4, 1, 15, 30)
825825
>>> format_datetime(dt, locale='en_US')
826-
u'Apr 1, 2007, 3:30:00 PM'
826+
u'Apr 1, 2007, 3:30:00\u202fPM'
827827
828828
For any pattern requiring the display of the timezone:
829829
830830
>>> format_datetime(dt, 'full', tzinfo=get_timezone('Europe/Paris'),
831831
... locale='fr_FR')
832-
'dimanche 1 avril 2007 à 17:30:00 heure d’été d’Europe centrale'
832+
'dimanche 1 avril 2007, 17:30:00 heure d’été d’Europe centrale'
833833
>>> format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
834834
... tzinfo=get_timezone('US/Eastern'), locale='en')
835835
u'2007.04.01 AD at 11:30:00 EDT'
@@ -864,7 +864,7 @@ def format_time(
864864
>>> from datetime import datetime, time
865865
>>> t = time(15, 30)
866866
>>> format_time(t, locale='en_US')
867-
u'3:30:00 PM'
867+
u'3:30:00\u202fPM'
868868
>>> format_time(t, format='short', locale='de_DE')
869869
u'15:30'
870870
@@ -905,7 +905,7 @@ def format_time(
905905
u'15:30:00 heure normale d\u2019Europe centrale'
906906
>>> format_time(t, format='full', tzinfo=get_timezone('US/Eastern'),
907907
... locale='en_US')
908-
u'3:30:00 PM Eastern Standard Time'
908+
u'3:30:00\u202fPM Eastern Standard Time'
909909
910910
:param time: the ``time`` or ``datetime`` object; if `None`, the current
911911
time in UTC is used
@@ -1137,7 +1137,7 @@ def format_interval(
11371137
'12:12\u201316:16'
11381138
11391139
>>> format_interval(time(5, 12), time(16, 16), "hm", locale="en_US")
1140-
'5:12 AM \u2013 4:16 PM'
1140+
'5:12\u202fAM\u2009\u20094:16\u202fPM'
11411141
11421142
>>> format_interval(time(16, 18), time(16, 24), "Hm", locale="it")
11431143
'16:18\u201316:24'
@@ -1156,7 +1156,7 @@ def format_interval(
11561156
'16:18:00\uff5e16:24:00'
11571157
11581158
>>> format_interval(date(2016, 1, 15), date(2016, 1, 17), "xxx", locale="de")
1159-
'15.01.2016 \u2013 17.01.2016'
1159+
'15.01.2016\u2009\u200917.01.2016'
11601160
11611161
:param start: First instant (datetime/date/time)
11621162
:param end: Second instant (datetime/date/time)

babel/numbers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,9 @@ def format_currency(
558558
"""Return formatted currency value.
559559
560560
>>> format_currency(1099.98, 'USD', locale='en_US')
561-
u'$1,099.98'
561+
'$1,099.98'
562562
>>> format_currency(1099.98, 'USD', locale='es_CO')
563-
u'US$\\xa01.099,98'
563+
u'US$1.099,98'
564564
>>> format_currency(1099.98, 'EUR', locale='de_DE')
565565
u'1.099,98\\xa0\\u20ac'
566566

babel/support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def datetime(
8383
>>> from babel.dates import get_timezone
8484
>>> fmt = Format('en_US', tzinfo=get_timezone('US/Eastern'))
8585
>>> fmt.datetime(datetime(2007, 4, 1, 15, 30))
86-
u'Apr 1, 2007, 11:30:00 AM'
86+
u'Apr 1, 2007, 11:30:00\u202fAM'
8787
"""
8888
return format_datetime(datetime, format, tzinfo=self.tzinfo, locale=self.locale)
8989

@@ -98,7 +98,7 @@ def time(
9898
>>> from babel.dates import get_timezone
9999
>>> fmt = Format('en_US', tzinfo=get_timezone('US/Eastern'))
100100
>>> fmt.time(datetime(2007, 4, 1, 15, 30))
101-
u'11:30:00 AM'
101+
u'11:30:00\u202fAM'
102102
"""
103103
return format_time(time, format, tzinfo=self.tzinfo, locale=self.locale)
104104

scripts/download_import_cldr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import zipfile
1010
from urllib.request import urlretrieve
1111

12-
URL = 'http://unicode.org/Public/cldr/41/cldr-common-41.0.zip'
13-
FILENAME = 'cldr-common-41.0.zip'
14-
# Via https://unicode.org/Public/cldr/41/hashes/SHASUM512
15-
FILESUM = 'c64f3338e292962817b043dd11e9c47f533c9b70d432f83e80654e20f4937c72b37e66a60485df43f734b1ff94ebf0452547a063076917889303c9653b4d6ce5'
12+
URL = 'http://unicode.org/Public/cldr/42/cldr-common-42.0.zip'
13+
FILENAME = 'cldr-common-42.0.zip'
14+
# Via https://unicode.org/Public/cldr/42/hashes/SHASUM512
15+
FILESUM = '315448fe6a9ac2d5a6a7fd1a27b38c5db30fed053654a803d50e3a8d06aa08ad153e8e57089fa094c561f41a54f37eecda0701b47a1813879902be71945aa38a'
1616
BLKSIZE = 131072
1717

1818

scripts/import_cldr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,10 @@ def parse_currency_formats(data, tree):
925925
)
926926
elif child.tag == 'pattern':
927927
pattern_type = child.attrib.get('type')
928+
if child.attrib.get('draft') or child.attrib.get('alt'):
929+
# Skip drafts and alternates.
930+
# The `noCurrency` alternate for currencies was added in CLDR 42.
931+
continue
928932
pattern = numbers.parse_pattern(str(child.text))
929933
if pattern_type:
930934
# This is a compact currency format, see:

tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ def test_date_formats_property(self):
228228
assert Locale('fr', 'FR').date_formats['long'].pattern == 'd MMMM y'
229229

230230
def test_time_formats_property(self):
231-
assert Locale('en', 'US').time_formats['short'].pattern == 'h:mm a'
231+
assert Locale('en', 'US').time_formats['short'].pattern == 'h:mm\u202fa'
232232
assert Locale('fr', 'FR').time_formats['long'].pattern == 'HH:mm:ss z'
233233

234234
def test_datetime_formats_property(self):
235-
assert Locale('en').datetime_formats['full'] == "{1} 'at' {0}"
235+
assert Locale('en').datetime_formats['full'] == "{1}, {0}"
236236
assert Locale('th').datetime_formats['medium'] == '{1} {0}'
237237

238238
def test_datetime_skeleton_property(self):

tests/test_date_intervals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_format_interval_same_instant_1():
1313

1414

1515
def test_format_interval_same_instant_2():
16-
assert dates.format_interval(TEST_DT, TEST_DT, "xxx", fuzzy=False, locale="fi") == "8.1.2016 klo 11.46.15"
16+
assert dates.format_interval(TEST_DT, TEST_DT, "xxx", fuzzy=False, locale="fi") == "8.1.2016 11.46.15"
1717

1818

1919
def test_format_interval_same_instant_3():
@@ -40,7 +40,7 @@ def test_format_interval_in_tz(timezone_getter):
4040
def test_format_interval_12_hour():
4141
t2 = TEST_DT
4242
t1 = t2 - datetime.timedelta(hours=1)
43-
assert dates.format_interval(t1, t2, "hm", locale="en") == "10:46 \u2013 11:46 AM"
43+
assert dates.format_interval(t1, t2, "hm", locale="en") == "10:46\u2009\u2013\u200911:46\u202fAM"
4444

4545

4646
def test_format_interval_invalid_skeleton():

tests/test_dates.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def test_get_datetime_format():
439439

440440

441441
def test_get_time_format():
442-
assert dates.get_time_format(locale='en_US').pattern == 'h:mm:ss a'
442+
assert dates.get_time_format(locale='en_US').pattern == 'h:mm:ss\u202fa'
443443
assert (dates.get_time_format('full', locale='de_DE').pattern ==
444444
'HH:mm:ss zzzz')
445445

@@ -460,19 +460,19 @@ def test_get_timezone_gmt(timezone_getter):
460460
def test_get_timezone_location(timezone_getter):
461461
tz = timezone_getter('America/St_Johns')
462462
assert (dates.get_timezone_location(tz, locale='de_DE') ==
463-
"Kanada (St. John\u2019s) Zeit")
463+
"Kanada (St. John\u2019s) (Ortszeit)")
464464
assert (dates.get_timezone_location(tz, locale='en') ==
465465
'Canada (St. John’s) Time')
466466
assert (dates.get_timezone_location(tz, locale='en', return_city=True) ==
467467
'St. John’s')
468468

469469
tz = timezone_getter('America/Mexico_City')
470470
assert (dates.get_timezone_location(tz, locale='de_DE') ==
471-
'Mexiko (Mexiko-Stadt) Zeit')
471+
'Mexiko (Mexiko-Stadt) (Ortszeit)')
472472

473473
tz = timezone_getter('Europe/Berlin')
474474
assert (dates.get_timezone_location(tz, locale='de_DE') ==
475-
'Deutschland (Berlin) Zeit')
475+
'Deutschland (Berlin) (Ortszeit)')
476476

477477

478478
@pytest.mark.parametrize(
@@ -564,16 +564,16 @@ def test_format_date():
564564
def test_format_datetime(timezone_getter):
565565
dt = datetime(2007, 4, 1, 15, 30)
566566
assert (dates.format_datetime(dt, locale='en_US') ==
567-
'Apr 1, 2007, 3:30:00 PM')
567+
'Apr 1, 2007, 3:30:00\u202fPM')
568568

569569
full = dates.format_datetime(
570570
dt, 'full',
571571
tzinfo=timezone_getter('Europe/Paris'),
572572
locale='fr_FR'
573573
)
574574
assert full == (
575-
'dimanche 1 avril 2007 à 17:30:00 heure '
576-
'd\u2019\xe9t\xe9 d\u2019Europe centrale'
575+
'dimanche 1 avril 2007, 17:30:00 heure '
576+
'd’été d’Europe centrale'
577577
)
578578
custom = dates.format_datetime(
579579
dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
@@ -585,7 +585,7 @@ def test_format_datetime(timezone_getter):
585585

586586
def test_format_time(timezone_getter):
587587
t = time(15, 30)
588-
assert dates.format_time(t, locale='en_US') == '3:30:00 PM'
588+
assert dates.format_time(t, locale='en_US') == '3:30:00\u202fPM'
589589
assert dates.format_time(t, format='short', locale='de_DE') == '15:30'
590590

591591
assert (dates.format_time(t, "hh 'o''clock' a", locale='en') ==
@@ -606,7 +606,7 @@ def test_format_time(timezone_getter):
606606
assert paris == '15:30:00 heure normale d’Europe centrale'
607607

608608
us_east = dates.format_time(t, format='full', tzinfo=eastern, locale='en_US')
609-
assert us_east == '3:30:00 PM Eastern Standard Time'
609+
assert us_east == '3:30:00\u202fPM Eastern Standard Time'
610610

611611

612612
def test_format_skeleton(timezone_getter):
@@ -720,7 +720,7 @@ def test_no_inherit_metazone_formatting(timezone_getter):
720720
# See: https://github.com/python-babel/babel/issues/428
721721
tz = timezone_getter('America/Los_Angeles')
722722
t = _localize(tz, datetime(2016, 1, 6, 7))
723-
assert dates.format_time(t, format='long', locale='en_US') == "7:00:00 AM PST"
723+
assert dates.format_time(t, format='long', locale='en_US') == "7:00:00\u202fAM PST"
724724
assert dates.format_time(t, format='long', locale='en_GB') == "07:00:00 Pacific Standard Time"
725725
assert dates.get_timezone_name(t, width='short', locale='en_US') == "PST"
726726
assert dates.get_timezone_name(t, width='short', locale='en_GB') == "Pacific Standard Time"

tests/test_numbers.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def test_get_territory_currencies():
300300

301301
assert numbers.get_territory_currencies('QO', date(2013, 1, 1)) == []
302302

303+
# Croatia uses Euro starting in January 2023; this is in CLDR 42.
304+
# See https://github.com/python-babel/babel/issues/942
305+
assert 'EUR' in numbers.get_territory_currencies('HR', date(2023, 1, 1))
306+
303307

304308
def test_get_decimal_symbol():
305309
assert numbers.get_decimal_symbol('en_US') == '.'
@@ -384,7 +388,7 @@ def test_format_currency():
384388
assert (numbers.format_currency(0, 'USD', locale='en_US')
385389
== '$0.00')
386390
assert (numbers.format_currency(1099.98, 'USD', locale='es_CO')
387-
== 'US$\xa01.099,98')
391+
== 'US$1.099,98')
388392
assert (numbers.format_currency(1099.98, 'EUR', locale='de_DE')
389393
== '1.099,98\xa0\u20ac')
390394
assert (numbers.format_currency(1099.98, 'EUR', '\xa4\xa4 #,##0.00',
@@ -396,11 +400,11 @@ def test_format_currency():
396400
locale='en_US')
397401
== '$1,099.98')
398402
assert (numbers.format_currency(1, 'USD', locale='es_AR')
399-
== 'US$\xa01,00') # one
403+
== 'US$1,00') # one
400404
assert (numbers.format_currency(1000000, 'USD', locale='es_AR')
401-
== 'US$\xa01.000.000,00') # many
405+
== 'US$1.000.000,00') # many
402406
assert (numbers.format_currency(0, 'USD', locale='es_AR')
403-
== 'US$\xa00,00') # other
407+
== 'US$0,00') # other
404408

405409

406410
def test_format_currency_format_type():
@@ -445,8 +449,8 @@ def test_format_compact_currency():
445449
assert numbers.format_compact_currency(1234, 'JPY', locale='ja_JP', format_type="short") == '¥1234'
446450
assert numbers.format_compact_currency(123456, 'JPY', locale='ja_JP', format_type="short") == '¥12万'
447451
assert numbers.format_compact_currency(123456, 'JPY', locale='ja_JP', format_type="short", fraction_digits=2) == '¥12.35万'
448-
assert numbers.format_compact_currency(123, 'EUR', locale='yav', format_type="short") == '123\xa0'
449-
assert numbers.format_compact_currency(12345, 'EUR', locale='yav', format_type="short") == '12K\xa0'
452+
assert numbers.format_compact_currency(123, 'EUR', locale='yav', format_type="short") == '\xa0123'
453+
assert numbers.format_compact_currency(12345, 'EUR', locale='yav', format_type="short") == '\xa012K'
450454
assert numbers.format_compact_currency(123456789, 'EUR', locale='de_DE', fraction_digits=1) == '123,5\xa0Mio.\xa0€'
451455

452456

@@ -480,7 +484,11 @@ def test_format_compact_currency_invalid_format_type():
480484
def test_format_currency_precision(input_value, expected_value):
481485
# Test precision conservation.
482486
assert numbers.format_currency(
483-
decimal.Decimal(input_value), 'USD', locale='en_US', decimal_quantization=False) == expected_value
487+
decimal.Decimal(input_value),
488+
currency='USD',
489+
locale='en_US',
490+
decimal_quantization=False,
491+
) == expected_value
484492

485493

486494
def test_format_currency_quantization():

0 commit comments

Comments
 (0)