Parser and validator for language codes (bcp47). Also exposes the IANA language code database
Project description
python-bcp47
A validating parser for bcp47 language codes
Data taken from IANA http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
bcp47 spec https://tools.ietf.org/html/bcp47
useful reading: https://www.w3.org/International/articles/language-tags/index.en
extension
and private-use
tag types are not currently supported
Python example
You can read languages
, extlangs
, scripts
, variants
, regions
, grandfathereds
, and redundant
language tag parts from dicts
on the bcp47
object.
They return OrderedDicts
>>> from bcp47 import bcp47
>>> list(bcp47["languages"].items())[:2]
[('aa', {'Subtag': 'aa', 'Description': ['Afar'], 'Added': '2005-10-16'}), ('ab', {'Subtag': 'ab', 'Description': ['Abkhazian'], 'Added': '2005-10-16', 'Suppress-Script': 'Cyrl'})]
>>> list(bcp47["regions"].items())[:2]
[('AA', {'Subtag': 'AA', 'Description': ['Private use'], 'Added': '2005-10-16'}), ('AC', {'Subtag': 'AC', 'Description': ['Ascension Island'], 'Added': '2009-07-29'})]
`
You can create a language code tag as follows
>>> tag = bcp47(language="en", region="GB")
>>> tag
<bcp47.code.BCP47Code 'en-GB' />
>>> tag.language
'en'
>>> tag.region
'GB'
You can also use a string or list of tag parts
>>> bcp47("en-GB")
<bcp47.code.BCP47Code 'en-GB' />
>>> bcp47("en", "GB")
<bcp47.code.BCP47Code 'en-GB' />
Creating a tag with invalid or unrecognized parameters raises an exception
>>> tag = bcp47(language="NOTALANGUAGE", region="GB")
Traceback (most recent call last):
...
Exception: Language 'NOTALANGUAGE' not recognized
>>> tag = bcp47("en-NOTAREGION")
Traceback (most recent call last):
...
Exception: Unrecognized tag part 'NOTAREGION'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-bcp47-0.0.3.tar.gz
.
File metadata
- Download URL: python-bcp47-0.0.3.tar.gz
- Upload date:
- Size: 101.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aa11976e47dd790dc072cba99655e5747b3ee25e694a62aa9d05288659937b8 |
|
MD5 | c9d2fec8c7381904262fb935dd34d9fa |
|
BLAKE2b-256 | 358cd8415f1afcbfe46b4d307a94a42d42ecec6d50fac5d6ce19791d046c4d5f |
File details
Details for the file python_bcp47-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: python_bcp47-0.0.3-py3-none-any.whl
- Upload date:
- Size: 105.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b43c0bf2c009da5f909035916dd05ab4c1963d5ed1db8a6c7a92098b8e737847 |
|
MD5 | 504b1c5d0efeaa1ab0eea584d630f903 |
|
BLAKE2b-256 | a67b26adaa2b0f59a7c1bbfd8310c39facc6d0ce0aaf39bced37404077bd9765 |