Introduction¶
This Python API offers a way to validate and lookup languages tags.
Import the module:
from language_tags import tags
To check whether the language_tag is valid use tags.check(). For example ‘nl-Be’ is valid but ‘nl-BE-BE’ is invalid.
> print(tags.check('nl-BE'))
True
> print(tags.check('nl-BE-BE'))
False
For meaningful error output see tags.tag().errors:
> errors = tags.tag('nl-BE-BE').errors
> for err in errors
> print(err.message)
Extra region subtag 'BE' found.
Lookup descriptions of tags:
> tags.description('nl-BE');
['Dutch', 'Flemish', 'Belgium']
Lookup descriptions of a language subtag:
> tags.language('nl').description;
['Dutch', 'Flemish']
Lookup tags by description:
> language_subtags = tags.search('Flemish')
> print(language_subtags[0].format)
'nl'
Get the language subtag of a tag:
> tags.tag('nl-BE').language
'{"subtag": "nl", "record": {"Subtag": "nl", "Suppress-Script": "Latn", "Added": "2005-10-16", "Type": "language", "Description": ["Dutch", "Flemish"]}, "type": "language"}'
For the complete api documentation see next chapter.