Module:taln-conj: Difference between revisions

Nehster9 (talk | contribs)
mNo edit summary
Nehster9 (talk | contribs)
mNo edit summary
Line 1: Line 1:
local p = {}
local p = {}
----------------------------------------------------------------
-- ENDINGS
----------------------------------------------------------------


local endings = {
local endings = {
Line 8: Line 12:
         pres_1p = "§1P_ARE§",
         pres_1p = "§1P_ARE§",
         pres_2p = "§2P_ARE§",
         pres_2p = "§2P_ARE§",
         pres_3p = "§3P_ARE§"
         pres_3p = "§3P_ARE§",
 
        past_1s = "§P1S_ARE§",
        past_2s = "§P2S_ARE§",
        past_3s = "§P3S_ARE§",
        past_1p = "§P1P_ARE§",
        past_2p = "§P2P_ARE§",
        past_3p = "§P3P_ARE§"
     },
     },


Line 17: Line 28:
         pres_1p = "ᠡᠨᠤᠰ",
         pres_1p = "ᠡᠨᠤᠰ",
         pres_2p = "ᠡᠴᠢᠰ",
         pres_2p = "ᠡᠴᠢᠰ",
         pres_3p = "ᠡᠨ"
         pres_3p = "ᠡᠨ",
 
        past_1s = "§P1S_ERE§",
        past_2s = "§P2S_ERE§",
        past_3s = "§P3S_ERE§",
        past_1p = "§P1P_ERE§",
        past_2p = "§P2P_ERE§",
        past_3p = "§P3P_ERE§"
     },
     },


Line 26: Line 44:
         pres_1p = "§1P_IRE§",
         pres_1p = "§1P_IRE§",
         pres_2p = "§2P_IRE§",
         pres_2p = "§2P_IRE§",
         pres_3p = "§3P_IRE§"
         pres_3p = "§3P_IRE§",
 
        past_1s = "§P1S_IRE§",
        past_2s = "§P2S_IRE§",
        past_3s = "§P3S_IRE§",
        past_1p = "§P1P_IRE§",
        past_2p = "§P2P_IRE§",
        past_3p = "§P3P_IRE§"
     }
     }
}
}
----------------------------------------------------------------
-- CLASS DETECTION
----------------------------------------------------------------


local function detect_class(title)
local function detect_class(title)
     if mw.ustring.match(title, "ᠠᠷᠡ$") then
     if mw.ustring.match(title, "ᠠᠷᠡ$") then
         return "are"
         return "are"
     elseif mw.ustring.match(title, "ᠡᠷᠡ$") then
     elseif mw.ustring.match(title, "ᠡᠷᠡ$") then
         return "ere"
         return "ere"
     elseif mw.ustring.match(title, "ᠢᠷᠡ$") then
     elseif mw.ustring.match(title, "ᠢᠷᠡ$") then
         return "ire"
         return "ire"
     end
     end
     return nil
     return nil
end
end


local function get_stem(title, class)
local function get_stem(title, class)
     if class == "are" then
     if class == "are" then
         return mw.ustring.gsub(title, "ᠠᠷᠡ$", "")
         return mw.ustring.gsub(title, "ᠠᠷᠡ$", "")
     elseif class == "ere" then
     elseif class == "ere" then
         return mw.ustring.gsub(title, "ᠡᠷᠡ$", "")
         return mw.ustring.gsub(title, "ᠡᠷᠡ$", "")
     elseif class == "ire" then
     elseif class == "ire" then
         return mw.ustring.gsub(title, "ᠢᠷᠡ$", "")
         return mw.ustring.gsub(title, "ᠢᠷᠡ$", "")
     end
     end
     return title
     return title
end
end
----------------------------------------------------------------
-- TRANSLITERATION
----------------------------------------------------------------


local translit = {
local translit = {
Line 72: Line 97:
     ["ᠲ"] = "t",
     ["ᠲ"] = "t",
     ["ᠨ"] = "n",
     ["ᠨ"] = "n",
    ["ᠺ"] = "c",
     ["ᠴ"] = "č"
     ["ᠴ"] = "č"
}
}


local function romanize(text)
local function romanize(text)
     local result = text
     local result = text
     for bichig, latin in pairs(translit) do
     for bichig, latin in pairs(translit) do
         result = mw.ustring.gsub(result, bichig, latin)
         result = mw.ustring.gsub(result, bichig, latin)
     end
     end
     return result
     return result
end
end


local function make_link(form)
----------------------------------------------------------------
-- DISPLAY HELPERS
----------------------------------------------------------------


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


function p.show(frame)
function p.show(frame)


     local args = frame:getParent().args
     local args = frame:getParent().args
     local title = mw.title.getCurrentTitle().text
     local title = mw.title.getCurrentTitle().text


     local class = args.class or detect_class(title)
     local class = args.class or detect_class(title)
     if not class then
     if not class then
         return "Error: could not determine conjugation class."
         return "Error: could not determine conjugation class."
Line 116: Line 139:


     for slot, ending in pairs(endings[class]) do
     for slot, ending in pairs(endings[class]) do
         if args[slot] and args[slot] ~= "" then
         if args[slot] and args[slot] ~= "" then
             forms[slot] = args[slot]
             forms[slot] = args[slot]
Line 122: Line 144:
             forms[slot] = stem .. ending
             forms[slot] = stem .. ending
         end
         end
    end
    local text =
        '{| class="wikitable mw-collapsible mw-collapsed"\n'
        .. '|+ Conjugation of [[' .. title .. ']] (<span style="color:#777777;">' .. romanize(title) .. '</span>)\n'
        ----------------------------------------------------------------
        -- HEADER
        ----------------------------------------------------------------


    end
        .. '|-\n'
        .. '! Mood !! Tense !! colspan="3" | Singular !! colspan="3" | Plural\n'
 
        .. '|-\n'
        .. '!  !!  !! 1st !! 2nd !! 3rd !! 1st !! 2nd !! 3rd\n'
 
        ----------------------------------------------------------------
        -- PRESENT
        ----------------------------------------------------------------
 
        .. '|-\n'
        .. '! Indicative !! Present\n'
        .. '| ' .. make_cell(forms.pres_1s)
        .. ' || ' .. make_cell(forms.pres_2s)
        .. ' || ' .. make_cell(forms.pres_3s)
        .. ' || ' .. make_cell(forms.pres_1p)
        .. ' || ' .. make_cell(forms.pres_2p)
        .. ' || ' .. make_cell(forms.pres_3p)
        .. '\n'


local text =
        ----------------------------------------------------------------
    '{| class="wikitable mw-collapsible mw-collapsed"\n'
        -- PAST
    .. '|+ Conjugation of [[' .. title .. ']] (<i>' .. romanize(title) .. '</i>)\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'
    .. '|-\n'
        .. '! Indicative !! Past\n'
    .. '! 1st !! 2nd !! 3rd !! 1st !! 2nd !! 3rd\n'
        .. '| ' .. make_cell(forms.past_1s)
        .. ' || ' .. make_cell(forms.past_2s)
        .. ' || ' .. make_cell(forms.past_3s)
        .. ' || ' .. make_cell(forms.past_1p)
        .. ' || ' .. make_cell(forms.past_2p)
        .. ' || ' .. make_cell(forms.past_3p)
        .. '\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
     return text