Module:tln-conj

From Linguifex
Revision as of 04:14, 20 June 2026 by Nehster9 (talk | contribs)
Jump to navigation Jump to search


local p = {}

local endings = {
    are = {
        pres_1s = "§1S_ARE§",
        pres_2s = "§2S_ARE§",
        pres_3s = "§3S_ARE§",
        pres_1p = "§1P_ARE§",
        pres_2p = "§2P_ARE§",
        pres_3p = "§3P_ARE§"
    },

    ere = {
        pres_1s = "ᠣ",
        pres_2s = "ᠡᠰ",
        pres_3s = "ᠡᠲ",
        pres_1p = "ᠡᠨᠤᠰ",
        pres_2p = "ᠡᠴᠢᠰ",
        pres_3p = "ᠡᠨ"
    },

    ire = {
        pres_1s = "§1S_IRE§",
        pres_2s = "§2S_IRE§",
        pres_3s = "§3S_IRE§",
        pres_1p = "§1P_IRE§",
        pres_2p = "§2P_IRE§",
        pres_3p = "§3P_IRE§"
    }
}

local function detect_class(title)

    if mw.ustring.match(title, "ᠠᠷᠡ$") then
        return "are"

    elseif mw.ustring.match(title, "ᠡᠷᠡ$") then
        return "ere"

    elseif mw.ustring.match(title, "ᠢᠷᠡ$") then
        return "ire"
    end

    return nil
end

local function get_stem(title, class)

    if class == "are" then
        return mw.ustring.gsub(title, "ᠠᠷᠡ$", "")

    elseif class == "ere" then
        return mw.ustring.gsub(title, "ᠡᠷᠡ$", "")

    elseif class == "ire" then
        return mw.ustring.gsub(title, "ᠢᠷᠡ$", "")
    end

    return title
end

local translit = {
    ["ᠠ"] = "a",
    ["ᠡ"] = "e",
    ["ᠢ"] = "i",
    ["ᠣ"] = "o",
    ["ᠤ"] = "u",
    ["ᠷ"] = "r",
    ["ᠸ"] = "v",
    ["ᠵ"] = "z",
    ["ᠰ"] = "s",
    ["ᠲ"] = "t",
    ["ᠨ"] = "n",
    ["ᠺ"] = "c",
    ["ᠴ"] = "č"
}

local function romanize(text)

    local result = text

    for bichig, latin in pairs(translit) do
        result = mw.ustring.gsub(result, bichig, latin)
    end

    return result
end

local function make_link(form)

    return
        '<div style="text-align:center;">'
        .. "[[" .. form .. "]]"
        .. "<br />"
        .. "<span style='color:#777777; font-size:90%;'>"
        .. romanize(form)
        .. "</span>"
        .. "</div>"
end

function p.show(frame)

    local args = frame:getParent().args

    local title = mw.title.getCurrentTitle().text

    local class = args.class or detect_class(title)

    if not class then
        return "Error: could not determine conjugation class."
    end

    local stem = get_stem(title, class)

    local forms = {}

    for slot, ending in pairs(endings[class]) do

        if args[slot] and args[slot] ~= "" then
            forms[slot] = args[slot]
        else
            forms[slot] = stem .. ending
        end

    end

local text =
    '{| class="wikitable mw-collapsible mw-collapsed"\n'
    .. '|+ Verb: [[' .. title .. ']] <small>(' .. romanize(title) .. ')</small>\n'

    -- header row 1
    .. '|-\n'
    .. '! rowspan="2" | Mood\n'
    .. '! rowspan="2" | Tense\n'
    .. '! colspan="3" | Singular\n'
    .. '! colspan="3" | Plural\n'

    -- header row 2
    .. '|-\n'
    .. '! 1st !! 2nd !! 3rd !! 1st !! 2nd !! 3rd\n'

    -- body
    .. '|-\n'
    .. '! Indicative\n'
    .. '! Present\n'
    .. '| ' .. make_link(forms.pres_1s)
    .. ' || ' .. make_link(forms.pres_2s)
    .. ' || ' .. make_link(forms.pres_3s)
    .. ' || ' .. make_link(forms.pres_1p)
    .. ' || ' .. make_link(forms.pres_2p)
    .. ' || ' .. make_link(forms.pres_3p)
    .. '\n'
    .. '|}'

    return text
end

return p