class Lingua:

    def __init__(self, abbr, code, full):
        self._abbr = abbr
        self._code = code
        self._full = full

    @property
    def abbr(self) -> str:
        return self._abbr

    @property
    def code(self) -> str:
        return self._code

    @property
    def full(self) -> str:
        return self._full

    def __str__(self):
        return self.code + ":" + self.full


ENGLISH = Lingua('E', 'en', 'English')
RUSSIAN = Lingua('R', 'ru', 'Russian')
UKRAINIAN = Lingua('U', 'ua', 'Ukrainian')

KNOWN = {
    "E": ENGLISH,
    "EN": ENGLISH,
    "ENGLISH": ENGLISH,
    "R": RUSSIAN,
    "RU": RUSSIAN,
    "RUSSIAN": RUSSIAN,
    "U": UKRAINIAN,
    "UA": UKRAINIAN,
    "UKRANIAN": UKRAINIAN,
    "UKRAINIAN": UKRAINIAN,
}


def detect(key: str) -> Lingua:
    return KNOWN.get(key.upper(), ENGLISH)


def code(locale):
    if locale is None:
        return None
    source = locale[0] if isinstance(locale, tuple) else str(locale)
    return source[:2]
