Module:User:Svartava2/getFirstLetter
- This module sandbox lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of Svartava2, for his own experimentation. Items in this module may be added and removed at Svartava2's discretion; do not rely on this module's stability.
local export = {}
local m_links = require("Module:links")
local m_translit = require("Module:sa-translit")
local PAGENAME = mw.title.getCurrentTitle().text
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local len = mw.ustring.len
local genders = {
["m"] = "masculine", ["f"] = "feminine", ["n"] = "neuter",
}
local cases = {
"Nominative", "Accusative", "Instrumental", "Dative", "Ablative",
"Genitive", "Locative", "Vocative"
}
function ending(tr)
return sub(tr, -1, -1)
end
function export.joinSuffix(frame, stem, suffixes, lang)
local output = ""
local term
local function to_Deva(tr)
local result = frame:expandTemplate{ title = 'chars', args = { 'sa', tr } }
return result
end
for _,suffix in ipairs(suffixes) do
if match(suffix, "^⌫⌫") then --backspace
term = sub(stem, 1, -3) .. sub(suffix, 3, -1)
elseif match(suffix, "^⌫") then --backspace
term = sub(stem, 1, -2) .. sub(suffix, 2, -1)
else
term = stem .. suffix
end
if output ~= "" then
output = output .. " <small style=\"color:888\">or</small> "
end
output = output .. m_links.full_link({lang = inc-pra, sc = require("Module:scripts").getByCode("Deva"), term = to_Deva(term)})
end
if output == "" then
output = "—"
end
return output
end
function export.show(frame, lang)
local args = frame:getParent().args
local g = args[1]
local word = args[2] or PAGENAME
local m_lang = require("Module:languages").getByCode(lang)
local data = {}
data['a'] = {
m = {{'⌫o'}, {'⌫ā'}, -- nom
{'ṃ'}, {'⌫e', '⌫ā'}, -- acc
{'⌫eṇa', '⌫eṇaṃ'}, {'⌫ehi', '⌫ehiṃ'}, -- ins
{'⌫āa'}, {nil}, -- dat
{'⌫āo', '⌫āu', '⌫ā', '⌫āhi', '⌫āhiṃto'}, {nil}, --abl
{'ssa'}, {'⌫āṇa', '⌫āṇaṃ'}, -- gen
{'mmi', '⌫e'}, {'⌫esu', '⌫esuṃ'}, -- loc
{'', '⌫ā'}, {'⌫ā'}, -- voc
},
n = {{'ṃ'}, {'⌫āiṃ', '⌫āi'}, -- nom
{'ṃ'}, {'⌫āiṃ', '⌫āi'}, -- acc
{'⌫eṇa', '⌫eṇaṃ'}, {'⌫ehi', '⌫ehiṃ'}, -- ins
{'⌫āa'}, {nil}, -- dat
{'⌫āo', '⌫āu', '⌫ā', '⌫āhi', '⌫āhiṃto'}, {nil}, --abl
{'ssa'}, {'⌫āṇa', '⌫āṇaṃ'}, -- gen
{'mmi', '⌫e'}, {'⌫esu', '⌫esuṃ'}, -- loc
{'', '⌫ā'}, {'⌫āiṃ', '⌫āi'}, -- voc
}
}
data['ā'] = {
f = {{''}, {'o', 'u', ''}, -- nom
{'⌫aṃ'}, {'o', 'u', ''}, -- acc
{'e', 'i', 'a'}, {'hi', 'hiṃ'}, -- ins
{nil}, {nil}, -- dat
{'o', 'u'}, {'hiṃto'}, --abl
{'e', 'i', 'a'}, {'ṇa', 'ṇaṃ'}, -- gen
{'e', 'i', 'a'}, {'su', 'suṃ'}, -- loc
{'⌫e', ''}, {'o', 'u', ''}, --voc
},
}
data['ā̈'] = data['ā']
data['i'] = {
f = {{'⌫ī'}, {'⌫īo', '⌫ī'}, -- nom
{'⌫iṃ'}, {'⌫īo', '⌫ī'}, -- acc
{'⌫īe'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
{nil}, {nil}, -- dat
{'⌫īo'}, {'⌫īhiṃto'}, --abl
{'⌫īe'}, {'⌫īṇa', '⌫īṇaṃ'}, -- gen
{'⌫īe'}, {'⌫īsu', '⌫īsuṃ'}, -- loc
{'⌫i', '⌫ī'}, {'⌫īo', '⌫ī'}, -- voc
},
m = {{'⌫ī'}, {'ṇo', '⌫ī', '⌫īo', '⌫ao', '⌫a-u'}, -- nom
{'ṃ'}, {'ṇo', '⌫ī', '⌫ao'}, -- acc
{'ṇā'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
{nil}, {nil}, -- dat
{'⌫īo', '⌫īu', 'ṇo', '⌫īhiṃto'}, {nil}, --abl
{'ssa', 'ṇo'}, {'⌫īṇa', '⌫īṇaṃ'}, -- gen
{'mmi'}, {'⌫īsu', '⌫īsuṃ'}, -- loc
{'', '⌫ī'}, {'ṇo', '⌫ī'}, -- voc
},
n = {{'ṃ', ''}, {'⌫īiṃ', '⌫īṇi', '⌫ī'}, -- nom
{'ṃ', ''}, {'⌫īiṃ', '⌫īṇi', '⌫ī'}, -- acc
{'ṇā'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
{nil}, {nil}, -- dat
{'⌫īo', '⌫īu', 'ṇo', '⌫īhiṃto'}, {nil}, --abl
{'ssa', 'ṇo'}, {'⌫īṇa', '⌫īṇaṃ'}, -- gen
{'mmi'}, {'⌫īsu', '⌫īsuṃ'}, -- loc
{'', '⌫ī'}, {'⌫īiṃ', '⌫īṇi', '⌫ī'}, -- voc
},
}
data['ī'] = {
f = {{''}, {'o', ''}, -- nom
{'⌫iṃ'}, {'o', ''}, -- acc
{'⌫īe'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
{nil}, {nil}, -- dat
{'o'}, {'hiṃto'}, --abl
{'e'}, {'ṇa', 'ṇaṃ'}, -- gen
{'e'}, {'su', 'suṃ'}, -- loc
{'⌫i', ''}, {'o', ''}, -- voc
},
}
data['u'] = {
f = {{'⌫ū'}, {'⌫ūo', '⌫ū'}, -- nom
{'⌫uṃ'}, {'⌫ūo', ''}, -- acc
{'⌫ūe'}, {'⌫ūhi', '⌫ūhiṃ'}, -- ins
{nil}, {nil}, -- dat
{'⌫ūo'}, {'⌫ūhiṃto'}, --abl
{'⌫ūe'}, {'⌫ūṇa', '⌫ūṇaṃ'}, -- gen
{'⌫ūe'}, {'⌫ūsu', '⌫ūsuṃ'}, -- loc
{'⌫u', '⌫ū'}, {'⌫ūo', '⌫ū'}, -- voc
},
m = {{'⌫ū'}, {'ṇo', '⌫ū', '⌫ūo', '⌫ao', '⌫a-u'}, -- nom
{'ṃ'}, {'ṇo', '⌫ū'}, -- acc
{'ṇā'}, {'⌫ūhi', '⌫ūhiṃ'}, -- ins
{'⌫ūo', '⌫ūu'}, {nil}, -- dat
{nil}, {nil}, --abl
{'ṇo', 'ssa'}, {'⌫ūṇa', '⌫ūṇaṃ'}, -- gen
{'mmi'}, {'⌫ūsu', '⌫ūsuṃ'}, -- loc
{'', '⌫ū'}, {nil}, -- voc
},
n = {{'ṃ', ''}, {'⌫ūiṃ', '⌫ūṇi', '⌫ū'}, -- nom
{'ṃ', ''}, {'⌫ūiṃ', '⌫ūṇi', '⌫ū'}, -- acc
{'ṇā'}, {'⌫ūhi', '⌫ūhiṃ'}, -- ins
{'⌫ūo', '⌫ūu'}, {nil}, -- dat
{nil}, {nil}, --abl
{'ṇo', 'ssa'}, {'⌫ūṇa', '⌫ūṇaṃ'}, -- gen
{'mmi'}, {'⌫ūsu', '⌫ūsuṃ'}, -- loc
{'', '⌫ū'}, {'⌫ūiṃ', '⌫ūṇi', '⌫ū'}, -- voc
},
}
data['ū'] = {
f = {{''}, {'o', ''}, -- nom
{'⌫uṃ'}, {'o', ''}, -- acc
{'e'}, {'hi', 'hiṃ'}, -- ins
{nil}, {nil}, -- dat
{'o'}, {'hiṃto'}, --abl
{'e'}, {'ṇa', 'ṇaṃ'}, -- gen
{'e'}, {'su', 'suṃ'}, -- loc
{'⌫u', ''}, {'o', ''}, -- voc
},
}
return data
end
local word_tr = m_translit.tr(word, m_lang, "Deva")
local ending = ending(word_tr)
if ending == '̈' then
ending = sub(word_tr, -2,-2)
end
local selected_data = data[ending][g]
local output = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="background:#FEFEFE; text-align:center; border: 1px solid #CCC;"
|- style="background: #d9ebff;"
! class="vsToggleElement" style="text-align: left;" colspan="3" |]=] .. sub(m_lang:getCanonicalName(), 1, -9) .. [=[ declension of ]=] .. word .. " (" .. genders[g] .. ")"
output = output .. [=[
|- class="vsHide"
! style="background:#eff7ff" |
! style="background:#eff7ff" | singular
! style="background:#eff7ff" | plural
]=]
for i,v in ipairs(cases) do
output = output .. "\n|- class=\"vsHide\"\n! style=\"background-color:#eff7ff;\" | " .. v
output = output .. "\n| " .. export.joinSuffix(frame, word_tr, selected_data[2 * i - 1], m_lang)
output = output .. "\n| " .. export.joinSuffix(frame, word_tr, selected_data[2 * i], m_lang)
end
output = output .. "\n|}"
return output