A Python package to validate BCP47 language tags
Project description
IANA-BCP47 (BCP47 Validator)
This project provides a Python implementation of a BCP47 language tag validator. It validates language tags based on the IANA Language Subtag Registry and ensures compliance with BCP47 specifications. The validator supports checking for redundant tags and validating custom language codes using dictionaries of subtags.
Features
- Validates BCP47 language tags with dictionaries derived from the IANA Language Subtag Registry.
- Supports validation for the following subtag types:
languageextlangscriptregionvariantredundant
- Provides detailed descriptions of valid language tags.
- Returns
Nonefor invalid tags.
How It Works
The project uses a generated Python module (bcp47.py) containing dictionaries for each type of subtag. Each language tag is validated as follows:
- The first subtag must match a valid language code.
- Subsequent subtags are validated against dictionaries for
extlang,script,region, andvariant. - Redundant tags (full language tags) are checked separately.
- Returns a description of the tag if valid or
Noneif invalid.
Usage
Validate a BCP47 Language Tag
Use the validate_bcp47 function to validate a language tag and retrieve its description.
from iana_bcp47.validator import validate_bcp47
# Example usage
tags = ["en", "en-US", "zh-Hant", "zh-Hant-CN", "invalid-tag"]
for tag in tags:
result = validate_bcp47(tag)
print(f"Tag '{tag}' is {'valid: ' + result if result else 'invalid'}.")
Output Example
Tag 'en' is valid: English.
Tag 'en-US' is valid: English - United States.
Tag 'zh-Hant' is valid: traditional Chinese.
Tag 'zh-Hant-CN' is valid: PRC Mainland Chinese in traditional script.
Tag 'invalid-tag' is invalid.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iana_bcp47-0.1.1.tar.gz.
File metadata
- Download URL: iana_bcp47-0.1.1.tar.gz
- Upload date:
- Size: 91.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4987a5be2f06282f65fe67940bd449b221d9f0e4d68fd4df73a15110c23b177c
|
|
| MD5 |
29d19c003b000b4234105384b0bbf8a0
|
|
| BLAKE2b-256 |
f352c2b6b31b07ba3b55211b68942614fd0688e70725f28c7841ba349eeca2db
|
Provenance
The following attestation bundles were made for iana_bcp47-0.1.1.tar.gz:
Publisher:
publish.yml on Masterain98/IANA-BCP47
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iana_bcp47-0.1.1.tar.gz -
Subject digest:
4987a5be2f06282f65fe67940bd449b221d9f0e4d68fd4df73a15110c23b177c - Sigstore transparency entry: 152965719
- Sigstore integration time:
-
Permalink:
Masterain98/IANA-BCP47@d228eaae6dcd7613c64867135b90bc2ccc4a5f12 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Masterain98
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d228eaae6dcd7613c64867135b90bc2ccc4a5f12 -
Trigger Event:
push
-
Statement type:
File details
Details for the file iana_bcp47-0.1.1-py3-none-any.whl.
File metadata
- Download URL: iana_bcp47-0.1.1-py3-none-any.whl
- Upload date:
- Size: 92.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4bb31f7f356bb7b8f16d1d661f9c49cadf06b7b286c3c85f5b4b16a3e0ff4c6
|
|
| MD5 |
05839241a32fb83b1f993c4641073709
|
|
| BLAKE2b-256 |
f4ac5ac4477cee9b7a65c13fdd3469b50a643b8ed9c0bbc67b41496c28e0d80a
|
Provenance
The following attestation bundles were made for iana_bcp47-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Masterain98/IANA-BCP47
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iana_bcp47-0.1.1-py3-none-any.whl -
Subject digest:
b4bb31f7f356bb7b8f16d1d661f9c49cadf06b7b286c3c85f5b4b16a3e0ff4c6 - Sigstore transparency entry: 152965720
- Sigstore integration time:
-
Permalink:
Masterain98/IANA-BCP47@d228eaae6dcd7613c64867135b90bc2ccc4a5f12 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Masterain98
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d228eaae6dcd7613c64867135b90bc2ccc4a5f12 -
Trigger Event:
push
-
Statement type: