Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

linguatag

BCP-47 language tags: standardization, distance, closest match, and the default region of a tag that names none.

from linguatag import closest_lang, default_region, lang_distance, with_default_region

default_region("en")            # 'GB'
with_default_region("zh-Hant")  # 'zh-Hant-TW'
lang_distance("pt", "pt-PT")    # 0
lang_distance("pt", "pt-BR")    # 5
closest_lang("en", ["en-US", "en-GB"])  # 'en-GB'
closest_lang("en-AU", ["fr-FR", "en-US"])  # 'en-US'

Default region

A tag with no region defaults to its motherland: the region where the language first appeared and is still spoken. en is en-GB, pt is pt-PT, es is es-ES.

CLDR likely-subtags is the base. CLDR picks the most-populous region, and for most languages that is also the motherland. linguatag.OVERRIDES replaces CLDR where the two differ, and each override cites its source: en is GB, pt is PT, ur is IN and yue is CN. An override holds for its own script only, so yue-Hant stays HK. When several countries share the area where a language first appeared, the CLDR pick is one of them and stays.

A bare ar is Modern Standard Arabic, the standard of no single country, so its region is 001, the world, as CLDR spells it.

linguatag/data/likely_regions.json holds the CLDR regions. scripts/build_likely_regions.py rebuilds it from the installed langcodes.

Distance and closest match

lang_distance is 0 for identical tags and grows as tags differ. A distance of 10 or less is a usable match. Both tags are standardized first, and a tag with no region is measured from its default region.

closest_lang returns the candidate with the smallest distance, verbatim, when that distance is within max_distance (default 10). Pass max_distance=0 to accept exact matches only.

An Arabic variety (arz, apc, ar-MA) in Arabic script is at most 5 from Modern Standard Arabic (ar, arb). No other macrolanguage gets this rule. Cantonese never matches Mandarin.

Install

pip install linguatag[langcodes]

langcodes is optional. Without it, standardization only folds case and underscores, and distance uses a coarse same-language measure with the same ordering.

Metadata

Release files for linguatag 0.0.2a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linguatag 0.0.2a1
File Size Uploaded Provenance Actions
linguatag-0.0.2a1.tar.gz 21.3 kB Without provenance Details for linguatag-0.0.2a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for linguatag 0.0.2a1
File Interpreter ABI Platform Actions
linguatag-0.0.2a1-py3-none-any.whl Python 3 none any Details for linguatag-0.0.2a1-py3-none-any.whl

Total release size: 38.5 kB

Release files / linguatag-0.0.2a1.tar.gz

Download URL linguatag-0.0.2a1.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ab404e5d237db02c1cef841ff9807a9330f626d2fca61e931e2720bb78c18dde
BLAKE2b-256 checksum
How to use checksums
e5511a09cf1e09287c87ad406cdbaf50f811f719102e1e6645a0d1157463d64e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / linguatag-0.0.2a1-py3-none-any.whl

Download URL linguatag-0.0.2a1-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75b1b0b49cae8d62f15b996b849df508f25cc49cdda94cf41151bf89bdcaa1fc
BLAKE2b-256 checksum
How to use checksums
e31832f426fedf8ec39cc1c774d250851c122c51db9b8184ee577348bbd73093
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for linguatag 0.0.2a1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page