"""This script generates locales based on ozi_core/data files."""

import glob  # pragma: no cover
import os  # pragma: no cover
import pprint  # pragma: no cover
from pathlib import Path  # pragma: no cover

import yaml  # pragma: no cover


def load_locale_data() -> dict[str, str]:  # pragma: no cover
    data = {}
    files = glob.glob(os.path.join(Path(__file__).parent / 'data', '*.yml'))
    for f in files:
        loc = os.path.splitext(os.path.basename(f))[0]
        with open(f, 'r', encoding='utf8') as fh:
            data[loc] = yaml.safe_load(fh)
    return data


if __name__ == '__main__':
    text = """# This file was generated by ozi_core.generate_locales DO NOT EDIT
data: dict[str, dict[str, str | None] | dict[str, str]] = {locales}"""
    print(
        text.format(
            locales=pprint.pformat(load_locale_data(), width=72).replace('{', '{\n', 1)
        ),
        file=open(Path(__file__).parent / '_locales.py', 'w', encoding='utf8'),
    )
