Skip to content

Commit

Permalink
Add language code definitions and test
Browse files Browse the repository at this point in the history
  • Loading branch information
pepe-rtmlab committed Feb 23, 2024
1 parent f6dba1e commit 393f4e9
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 0 deletions.
189 changes: 189 additions & 0 deletions pydantic_extra_types/language_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
from typing import Literal

# language code definition as defined in ISO 639-3 https://en.wikipedia.org/wiki/ISO_639-3
LanguageCode = Literal[
'aar',
'abk',
'afr',
'aka',
'alb',
'amh',
'ara',
'arg',
'arm',
'asm',
'ava',
'ave',
'aym',
'aze',
'bak',
'bam',
'baq',
'bel',
'ben',
'bih',
'bis',
'bos',
'bre',
'bul',
'bur',
'cat',
'cha',
'che',
'chi',
'chu',
'chv',
'cor',
'cos',
'cre',
'cze',
'dan',
'div',
'dut',
'dzo',
'eng',
'epo',
'est',
'ewe',
'fao',
'fij',
'fin',
'fre',
'fry',
'ful',
'geo',
'ger',
'gla',
'gle',
'glg',
'glv',
'gre',
'grn',
'guj',
'hat',
'hau',
'heb',
'her',
'hin',
'hmo',
'hrv',
'hun',
'ibo',
'ice',
'ido',
'iii',
'iku',
'ile',
'ina',
'ind',
'ipk',
'ita',
'jav',
'jpn',
'kal',
'kan',
'kas',
'kau',
'kaz',
'khm',
'kik',
'kin',
'kir',
'kom',
'kon',
'kor',
'kua',
'kur',
'lao',
'lat',
'lav',
'lim',
'lin',
'lit',
'ltz',
'lub',
'lug',
'mac',
'mah',
'mal',
'mao',
'mar',
'may',
'mlg',
'mlt',
'mon',
'nau',
'nav',
'nbl',
'nde',
'ndo',
'nep',
'nno',
'nob',
'nor',
'nya',
'oci',
'oji',
'ori',
'orm',
'oss',
'pan',
'per',
'pli',
'pol',
'por',
'pus',
'que',
'roh',
'rum',
'run',
'rus',
'sag',
'san',
'sin',
'slo',
'slv',
'sme',
'smo',
'sna',
'snd',
'som',
'sot',
'spa',
'srd',
'srp',
'ssw',
'sun',
'swa',
'swe',
'tah',
'tam',
'tat',
'tel',
'tgk',
'tgl',
'tha',
'tib',
'tir',
'ton',
'tsn',
'tso',
'tuk',
'tur',
'twi',
'uig',
'ukr',
'urd',
'uzb',
'ven',
'vie',
'vol',
'wel',
'wln',
'wol',
'xho',
'yid',
'yor',
'zha',
'zul'
]
18 changes: 18 additions & 0 deletions tests/test_language_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
from pydantic import BaseModel, ValidationError

from pydantic_extra_types.language_code import LanguageCode


class CheckingModel(BaseModel):
lang: LanguageCode


def test_language_ok():
model = CheckingModel(lang='eng')
assert model.lang == 'eng'


def test_language_fail():
with pytest.raises(ValidationError):
CheckingModel(lang='en-US')

0 comments on commit 393f4e9

Please sign in to comment.