Language Tags

1.2.0 · active · verified Sat Apr 11

This project is a Python version of the language-tags Javascript project. It provides an API to validate and lookup language tags based on BCP 47 (RFC 5646) and the latest IANA language subtag registry. It is actively maintained, with updates released as the underlying standards change.

Warnings

Install

Imports

Quickstart

Initializes a Tag object from a BCP 47 string, checks its validity, and demonstrates how to access its primary language, region, script, and human-readable description components.

from language_tags import Tag

# Create a Tag object from a BCP 47 string
tag = Tag('en-US')

# Check if the tag is valid according to the IANA registry
print(f"'{tag}' is valid: {tag.is_valid()}")

# Access components of the tag
print(f"Language: {tag.language()}")
print(f"Region: {tag.region()}")

# Script might be None if not explicitly present or suppressed
print(f"Script: {tag.script()}")
print(f"Description: {tag.description()}")

# Example of an invalid tag
invalid_tag = Tag('xx-YYY')
print(f"\n'{invalid_tag}' is valid: {invalid_tag.is_valid()}")

view raw JSON →