Skip to content

locale

available_locales = [(LocaleModel.model_fields['language'].default) for LocaleModel in (get_args(get_args(Locale.__value__)[0]))] module-attribute

locale_adapter = pydantic.TypeAdapter(Locale) module-attribute

Locale = Annotated[EnglishLocale | reduce(or_, discover_other_locales()), pydantic.Field(discriminator=language)]

discover_other_locales()

Auto-discover and load locale variant classes from other_locales/ directory.

Why

Locales beyond English are defined as YAML files with translations and format overrides. Dynamic discovery enables community-contributed locales without core code changes.

Returns:

  • list[type[EnglishLocale]]

    List of dynamically generated locale variant classes.

Source code in src/rendercv/schema/models/locale/locale.py
def discover_other_locales() -> list[type[EnglishLocale]]:
    """Auto-discover and load locale variant classes from other_locales/ directory.

    Why:
        Locales beyond English are defined as YAML files with translations
        and format overrides. Dynamic discovery enables community-contributed
        locales without core code changes.

    Returns:
        List of dynamically generated locale variant classes.
    """
    other_locales_dir = Path(__file__).parent / "other_locales"
    discovered: list[type[EnglishLocale]] = []

    for yaml_file in sorted(other_locales_dir.glob("*.yaml")):
        locale_model = create_variant_pydantic_model(
            variant_name=yaml_file.stem,
            defaults=read_yaml(yaml_file)["locale"],
            base_class=EnglishLocale,
            discriminator_field="language",
            class_name_suffix="Locale",
            module_name="rendercv.schema.models.locale",
        )
        discovered.append(locale_model)

    return discovered