'Locale',
'UnknownLocaleError',
'default_locale',
+ 'get_cldr_version',
'get_global',
'get_locale_identifier',
'negotiate_locale',
_GLOBAL_KEY: TypeAlias = Literal[
"all_currencies",
+ "cldr",
"currency_fractions",
"language_aliases",
"likely_subtags",
The keys available are:
- ``all_currencies``
+ - ``cldr`` (metadata)
- ``currency_fractions``
- ``language_aliases``
- ``likely_subtags``
lang, territory, script, variant, modifier = tup + (None,) * (5 - len(tup))
ret = sep.join(filter(None, (lang, script, territory, variant)))
return f'{ret}@{modifier}' if modifier else ret
+
+
+def get_cldr_version() -> str:
+ """Return the Unicode CLDR version used by this Babel installation.
+
+ Generally, you should be able to assume that the return value of this
+ function is a string representing a version number, e.g. '47'.
+
+ >>> get_cldr_version()
+ '47'
+
+ .. versionadded:: 2.18
+
+ :rtype: str
+ """
+ return str(get_global("cldr")["version"])
.. autofunction:: parse_locale
.. autofunction:: get_locale_identifier
+
+.. autofunction:: get_cldr_version
def parse_global(srcdir, sup):
global_data = {}
+
+ with open(os.path.join(srcdir, 'dtd', 'ldml.dtd')) as dtd_file:
+ cldr_version_match = re.search(
+ r'<!ATTLIST version cldrVersion CDATA #FIXED "(.+?)"',
+ dtd_file.read(),
+ )
+ if not cldr_version_match:
+ raise ValueError("Could not find CLDR version in DTD file")
+ cldr_version = cldr_version_match.group(1)
+ global_data.setdefault('cldr', {})['version'] = cldr_version
+
+ log.info('Processing CLDR version %s from %s', cldr_version, srcdir)
+
sup_dir = os.path.join(srcdir, 'supplemental')
territory_zones = global_data.setdefault('territory_zones', {})
zone_aliases = global_data.setdefault('zone_aliases', {})
Locale.parse(None)
with pytest.raises(TypeError, match="Empty"):
Locale.parse(False) # weird...!
+
+
+def test_get_cldr_version():
+ assert core.get_cldr_version() == "47"