def get_wagtail_source_locale()

in src/wagtail_localize_smartling/utils.py [0:0]


def get_wagtail_source_locale(project: "Project") -> Locale | None:
    """
    Returns the Wagtail Locale that is compatible with the Smartling project's
    source locale if one exists, None otherwise.

    The Smartling source locale is compatible if a matching Locale exists in the
    database and that locale isn't syncing from any other Locale.
    """
    from .models import Project

    project = Project.get_current()

    # TODO factor in LANGUAGE_CODE

    try:
        locale = Locale.objects.get_for_language(project.source_locale_id)  # pyright: ignore[reportAttributeAccessIssue]
    except Locale.DoesNotExist:
        return None

    if LocaleSynchronization.objects.filter(locale=locale).exists():
        return None

    return locale