parse_locale(identifier,
sep=' _ ' )
|
|
Parse a locale identifier into a tuple of the form:
``(language, territory, script, variant)``
>>> parse_locale('zh_CN')
('zh', 'CN', None, None)
>>> parse_locale('zh_Hans_CN')
('zh', 'CN', 'Hans', None)
The default component separator is "_", but a different separator can be
specified using the sep parameter:
>>> parse_locale('zh-CN', sep='-')
('zh', 'CN', None, None)
If the identifier cannot be parsed into a locale, a ValueError exception
is raised:
>>> parse_locale('not_a_LOCALE_String')
Traceback (most recent call last):
...
ValueError: 'not_a_LOCALE_String' is not a valid locale identifier
- Parameters:
identifier - the locale identifier string
sep - character that separates the different components of the locale
identifier
- Returns:
tuple
- the (language, territory, script, variant) tuple
- Raises:
ValueError - if the string does not appear to be a valid locale
identifier
|