validator-collection icon indicating copy to clipboard operation
validator-collection copied to clipboard

Support Language Code validation

Open insightindustry opened this issue 3 years ago • 0 comments

It would be good to support the validation of Language Codes in line with ISO 639-1, ISO 639-2, and IETF BCP47, etc.

Given the mess in global language code standards, and the different schemas used in different contexts (i18n vs L10n, etc.) it'll be important to provide a pretty comprehensive implementation.

The basic syntax will need to be:

  • validators.language_code(value, ..., standard = None) which returns the validated language code where:
    • value may either be a direct language code in one of the standard schemas OR the "human readable" expansion of the language (e.g. "English" which would validate to "en", or "American English" (country + language) which would validate to "en_US".
    • standard indicates the standard against which it should be validated, but which defaults to validated against all standards
  • checkers.is_language_code(value) which validates against validators.language_code()
  • validators.language(value, ..., standard = None) which returns the validated human-readable language (e.g. "English" or "American English") with standard title-case applied:
    • value is a language code in one of the standard schemas (which can be narrowed down using standard) OR a human readable language (e.g. "english" or "American english")
    • standard indicates the standard schema against which it should be validated, but which defaults to validation against all standards
  • checkers.is_language(value) which validates against validators.language()

insightindustry avatar Jan 09 '21 02:01 insightindustry