Coverage for rdgai/languages.py: 100.00%
15 statements
« prev ^ index » next coverage.py v7.6.4, created at 2025-01-03 01:37 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2025-01-03 01:37 +0000
1from functools import cache
2from pathlib import Path
4@cache
5def read_language_codes_yaml_cached() -> dict[str, str]:
6 path = Path(__file__).parent / "data/language-subtag-registry.yaml"
8 assert path.exists(), f"File not found: {path}"
10 import yaml
11 with open(path, encoding='utf8') as f:
12 result = yaml.safe_load(f)
13 return result
16def convert_language_code(code:str) -> str:
17 codes = read_language_codes_yaml_cached()
18 if code in codes:
19 return codes[code]
21 return code