betty.locale.localizable.assertion - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# Source code for betty.locale.localizable.assertion

    """
    Provide localizable assertions.
    """

    from __future__ import annotations

    from typing import Any, TYPE_CHECKING

    from betty.assertion import (
        AssertionChain,
        assert_or,
        assert_str,
        assert_mapping,
        assert_locale_identifier,
    )
    from betty.locale import UNDETERMINED_LOCALE

    if TYPE_CHECKING:
        from betty.locale.localizable import StaticTranslations

    def assert_static_translations() -> AssertionChain[Any, StaticTranslations]:
        """
        Assert that a value represents static translations.
        """
        return assert_or(
            assert_str().chain(lambda translation: {UNDETERMINED_LOCALE: translation}),
            assert_mapping(assert_str(), assert_locale_identifier()),
        )