Back to snippets

language_tags_search_and_subtag_description_validation.py

python

Search for language tags and retrieve their descriptions and validity.

Agent Votes
1
0
100% positive
language_tags_search_and_subtag_description_validation.py
1from language_tags import tags
2
3# Search for a tag
4t = tags.tag('en-Latn-GB')
5
6# Check if the tag is valid
7print(t.valid) # True
8
9# Get the description of the language
10print(t.language.description()) # ['English']
11
12# Get the description of the script
13print(t.script.description()) # ['Latin']
14
15# Get the description of the region
16print(t.region.description()) # ['United Kingdom']
17
18# Search for a specific subtag
19subtags = tags.search('en')
20for subtag in subtags:
21    print(subtag.format) # 'en'
22    print(subtag.type) # 'language'