Skip to content

Supposedly valid Language instances may have invalid tags #55

@dscorbett

Description

@dscorbett

Language.get normalizes case and enforces syntactic validity whereas Language.make doesn’t. This causes some discrepancies. I presume that a user is not supposed to have to worry about case or syntactic validity once they have a valid (in the sense of is_valid) Language object.

If Language is valid, its tag should presumably be valid. This is not always true.

>>> lang = Language.make(language='Latn')
>>> lang.is_valid()
True
>>> tag_is_valid(lang.to_tag())
False
>>> 
>>> lang = Language.make(script='Qaaa..Qabx')
>>> lang.is_valid()
True
>>> tag_is_valid(lang.to_tag())
False
>>> 
>>> lang = Language.make(extensions='t-fr')
>>> lang.is_valid()
True
>>> tag_is_valid(lang.to_tag())
False
>>> 
>>> lang = Language.make(extensions=['a'])
>>> lang.is_valid()
True
>>> tag_is_valid(lang.to_tag())
False
>>> 
>>> lang = Language.make(language='x-') 
>>> lang.is_valid()
True
>>> tag_is_valid(lang.to_tag())
False

Round-tripping a valid Language through its tag should presumably return an equivalent Language. This is not always true.

>>> lang = Language.make(language='FR')
>>> lang.is_valid()
True
>>> lang == Language.get(lang.to_tag(), normalize=False)
False

Alternatively, maybe it is the user’s responsibility to normalize case and check for syntactic validity before calling Language.make. I don’t think the documentation actually says that though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions