local export = {}
local m_translit = require("Module:mr-translit")
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local match = mw.ustring.match
local len = mw.ustring.len
local genders = {
= 'masculine', = 'feminine', = 'neuter',
}
local function wordify(text)
local words, translits = {}, {}
for word in mw.text.gsplit(text, ",") do
table.insert(words, mr_format(word))
table.insert(translits, m_translit.tr(word, "mr", "Deva"))
end
text = table.concat(words, ", ") .. "<br><small style=\"color:#888\">" ..
table.concat(translits, ", ") .. "</small>"
return text
end
function mr_format(text)
text = ('<span lang="mr" class="Deva">]</span>'):format(text)
return text
end
local function stem(word)
return sub(word, 1, -2)
end
local function stem_ending(word)
return sub(word, -1)
end
local function s_obl(word, g)
local ending = stem_ending(word)
local stem = stem(word)
data = {
= { = word, = stem .. "्या", = stem .. "वा", = word .. "ा"},
= { = word, = stem .. "े", = word .. "ी"},
= { = word .. "े"},
= { = stem .. "्या", = stem .. "्या", = word .. "ा"}
}
return data or data
end
local function p_dir(word, g)
local ending = stem_ending(word)
local stem = stem(word)
data = {
= { = stem .. "े", = word },
= { = stem .. "्या", = word, = word .. "ी"},
= { = word .. "ा"},
= { = stem .. "ं", -- TODO: alternately final "e"
= stem .. "ी",
= stem .. "ं" -- TODO: alternately final "e"
}
}
-- it's ugly but it works ^_^
if g == "n" and (stem_ending(m_translit.tr(word)) == "a" or ending == "ी") then
return word
end
return data or data
end
function export.show(frame)
local args = frame:getParent().args
local word = args or mw.title.getCurrentTitle().text
local g = args or args
data = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="background:#FEFEFE; text-align:center; border: 1px solid #CCC; min-width:30%"
|- style="background: #d9ebff;"
! class="vsToggleElement" style="text-align: left;" colspan="4" | Declension of ]=] .. mr_format(word) .. " " .. genders
data = data .. [=[
|- class="vsShow"
| style="background:#eff7ff" | ''dir. sg.''
| ]=] .. wordify(word) .. [=[
|- class="vsShow"
| style="background:#eff7ff" | ''dir. pl.''
| ]=] .. wordify(p_dir(word, g))
data = data .. [=[
|- class="vsHide"
! style="background:#eff7ff" | nominative
| ]=] .. wordify(word) .. "||" .. wordify(p_dir(word, g))
data = data .. [=[
|- class="vsHide"
! style="background:#eff7ff" | oblique
| ]=] .. wordify(s_obl(word, g)) .. "||" .. wordify(s_obl(word, g) .. "ं")
data = data .. [=[
|- class="vsHide"
! style="background:#eff7ff" | dative
| ]=] .. wordify(s_obl(word, g) .. "ला") .. "||" .. wordify(s_obl(word, g) .. "ंना")
data = data .. [=[
|- class="vsHide"
! style="background:#eff7ff" | ergative
| ]=] .. wordify(s_obl(word, g) .. "ने") .. "||" .. wordify(s_obl(word, g) .. "ंनी")
data = data .. [=[
|- class="vsHide"
! style="background:#eff7ff" | instrumental
| ]=] .. wordify(s_obl(word, g) .. "शी") .. "||" .. wordify(s_obl(word, g) .. "ंशी")
data = data .. [=[
|- class="vsHide"
! style="background:#eff7ff" | locative
| ]=] .. wordify(s_obl(word, g) .. "त") .. "||" .. wordify(s_obl(word, g) .. "ंत")
data = data .. [=[
|- class="vsHide"
! style="background:#eff7ff" | vocative
| ]=] .. wordify(s_obl(word, g)) .. "||" .. wordify(s_obl(word, g) .. "ंनो")
data = data .. [=[
|}]=]
return data
end
return export