Module:User:Sinonquoi/pa-nouns

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Sinonquoi, for their own experimentation. Items in this module may be added and removed at Sinonquoi's discretion; do not rely on this module's stability.


local m_translit = require("Module:pa-translit")
local export = {}

local function wordify(text)
	local words, translits = {}, {}
	for word in mw.text.gsplit(text, ",") do
		table.insert(words, pa_format(word))
		table.insert(translits, m_translit.tr(word, "pa", "Guru"))
	end
	text = table.concat(words, ", ") .. "<br/><span style=\"color:#888\">" .. table.concat(translits, ", ") .. "</span>"
	return text
end

function pa_format(text) 
	text = ('<span lang="pa" class="Guru">[[%s]]</span>'):format(text)
	return text
end

local function decline(word, gender)
	if gender == "f" then
		if match(word, "ਅਆਇਈਉਊਓਔਏਐ$") then
			obl_sg, voc_sg, nom_pl, obl_pl, voc_pl = word, word .. "ਏ", word .. "ਆੰ", word .. "ਆੰ", word.. "ਓ"
		--else 
		--	obl_sg, voc_sg, nom_pl, obl_pl, voc_pl = word, word .. "ੇ", word .. "ਾੰ", word .. "ਾੰ", word.. "ੋ"
		end
	elseif gender == "m" then
		if match(word, "ਾ$") then
			local stem = mw.text.trim(word, "ਾ$")
			obl_sg, voc_sg, nom_pl, obl_pl, voc_pl = stem, stem .. "ਏ", stem .. "ਆੰ", stem .. "ਆੰ", stem .. "ਓ"
		end
	end
	return obl_sg, voc_sg, nom_pl, obl_pl, voc_pl
end

local function make_row(case, s, p)
	local data = {}
	
	table.insert(data, [=[
		|- class="vsHide"
		| style="background:#eff7ff" | '' ]=] .. case .. "''")
	table.insert(data, '|' .. wordify(s))
	table.insert(data, '|' .. wordify(p))
	
	return table.concat(data, "\n")
end

function export.show(frame)
	local args = frame:getParent().args
--	local args = require("Module:parameters").process(frame:getParent().args, params)
--	local word = args[2] or mw.title.getCurrentTitle().text
	local word = "ਬਾਰੀ"
	local gender = args["g"]
	
	local obl_sg, voc_sg, nom_pl, obl_pl, voc_pl = decline(word, gender)
	local nom_sg = word
	
	local data = {'{| class="inflection-table vsSwitcher vsToggleCategory-inflection" style="background:#F9F9F9; text-align:center; border: 1px solid #CCC; width: 35em;"'}
	table.insert(data, '|- style="background: #d9ebff;"')
	table.insert(data, '! class="vsToggleElement" style="text-align:left;" colspan="3" | Declension of ' .. pa_format(word))
	table.insert(data, [=[
		|- class="vsHide"
		! style="background:#eff7ff" |
		! style="background:#eff7ff" | Singular
		! style="background:#eff7ff" | Plural]=])
	table.insert(data, make_row("Direct", nom_sg, nom_pl))
	table.insert(data, make_row("Oblique", obl_sg, obl_pl))
	table.insert(data, make_row("Vocative", voc_sg, voc_pl))
	table.insert(data, "|}")
	
	return table.concat(data, "\n")
end

return export