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

1from functools import cache 

2from pathlib import Path 

3 

4@cache 

5def read_language_codes_yaml_cached() -> dict[str, str]: 

6 path = Path(__file__).parent / "data/language-subtag-registry.yaml" 

7 

8 assert path.exists(), f"File not found: {path}" 

9 

10 import yaml 

11 with open(path, encoding='utf8') as f: 

12 result = yaml.safe_load(f) 

13 return result 

14 

15 

16def convert_language_code(code:str) -> str: 

17 codes = read_language_codes_yaml_cached() 

18 if code in codes: 

19 return codes[code] 

20 

21 return code