Modul:lettgallisch.substantivflexion

Aus Wiktionary, dem freien Wörterbuch

Die Dokumentation für dieses Modul kann unter Modul:lettgallisch.substantivflexion/Doku erstellt werden

local flex = {}

-- optionale Parameter
-- args[1] = <Deklinationsform> {f,m}
-- args[2] = <Palatisierung> {0,1}
-- args["test"] == 1 zur Testausgabe

local function makeRow(head, sing, plur)
	local row = mw.html.create('tr')
	row
			:tag('td')
				:css('font-weight', 'bold')
				:css('background-color', '#F4F4F4')
				:wikitext(head)
			:tag('td')
				:wikitext(sing)
			:tag('td')
				:wikitext(plur)
	return tostring(row)
end
local function makeTestRow(head, sing, plur, sing_t, plur_t)
	if sing~=sing_t then sing=sing .. " <font color=red>" .. sing_t .. "</font>" end 
	if plur~=plur_t then plur=plur .. " <font color=red>" .. plur_t .. "</font>" end 
	return tostring(makeRow(head, sing, plur))
end

function flex.deklination(frame)
	local stem = ""
	local args
	local pal = {}
	local depal = {}
	pal["c"] = "č"
	pal["d"] = "ž"
	pal["s"] = "š"
	pal["t"] = "š"
	pal["z"] = "ž"
	pal["l"] = "ļ"
	pal["n"] = "ņ"
	pal["sl"] = "šļ"
	pal["sn"] = "šņ"
	pal["sm"] = "šm"
	pal["zl"] = "žļ"
	pal["zn"] = "žņ"
	pal["kst"] = "kš"
	depal["ļ"] = "l"
	depal["ņ"] = "n"
    if frame == mw.getCurrentFrame() then
        args = frame:getParent().args
    else
        args = frame.args
    end
	local s = {}
	local p = {}
	local t = args["test"]
	local dk = args[1] or ""
	local root = mw.html.create('table')
	s[1] = args["Nominativ Singular"] or mw.title.getCurrentTitle().text
	e1 = mw.ustring.sub(s[1],-1)
	e2 = mw.ustring.sub(s[1],-2)

	if dk=="m3" then 
		stem = mw.ustring.sub(s[1],1,-3)
		s[2] = s[1]
		s[3] = stem .. "um"
		s[4] = stem .. "u"
		s[5] = stem .. "u"
		s[6] = stem .. "ū"
		s[7] = s[1]
	elseif (dk=="f") then
		stem = mw.ustring.sub(s[1],1,-2)
		s[2] = s[1]
		s[3] = stem .. "ei"
		s[4] = stem .. "i"
		s[5] = s[4]
		s[6] = stem .. "ī"
		s[7] = s[1]
		p[1] = s[1] .. ", " .. stem .. "is"
		p[3] = stem .. "im"
		p[4] = p[1]
		p[5] = p[3]
		p[6] = s[6] .. "s"
		p[7] = p[1]
		cons = mw.ustring.sub(stem,-1)
		cons2 = mw.ustring.sub(stem,-2)
		cons3 = mw.ustring.sub(stem,-3)
		p[2] = stem .. "u"
		if pal[cons] then
			p[2] = mw.ustring.sub(stem,1,-2) .. pal[cons] .. "u"
		end
		if pal[cons2] then
			p[2] = mw.ustring.sub(stem,1,-3) .. pal[cons2] .. "u"
		end
		if pal[cons3] then
			p[2] = mw.ustring.sub(stem,1,-4) .. pal[cons3] .. "u"
		end
	elseif dk=="m2" or ((e2=="is") and dk=="")  then 
		if (e2=="is") then stem = mw.ustring.sub(s[1],1,-3) else stem = mw.ustring.sub(s[1],1,-2) end
		s[2] = stem .. "a"
		s[3] = stem .. "am"
		s[4] = stem .. "i"
		s[5] = s[4]
		s[6] = stem .. "ī"
		s[7] = stem .. "i"
		p[1] = stem .. "i"
		p[2] = stem .. "u"
		p[6] = stem .. "ūs"
		cons = mw.ustring.sub(stem,-1)
		cons2 = mw.ustring.sub(stem,-2)
		if depal[cons] then 
			s[4] = mw.ustring.sub(stem,1,-2) .. depal[cons] .. "i"
			s[5] = s[4]
			s[6] = mw.ustring.sub(stem,1,-2) .. depal[cons] .. "ī"
			p[1] = s[4]
		end
		if pal[cons] then
			s[2] = mw.ustring.sub(stem,1,-2) .. pal[cons] .. "a"
			s[3] = mw.ustring.sub(stem,1,-2) .. pal[cons] .. "am"
			p[1] = mw.ustring.sub(stem,1,-2) .. pal[cons] .. "i"
			p[2] = mw.ustring.sub(stem,1,-2) .. pal[cons] .. "u"
			p[6] = mw.ustring.sub(stem,1,-2) .. pal[cons] .. "ūs"
		end
		if pal[cons2] then
			s[2] = mw.ustring.sub(stem,1,-3) .. pal[cons2] .. "a"
			s[3] = mw.ustring.sub(stem,1,-3) .. pal[cons2] .. "am"
			p[1] = mw.ustring.sub(stem,1,-3) .. pal[cons2] .. "i"
			p[2] = mw.ustring.sub(stem,1,-3) .. pal[cons2] .. "u"
			p[6] = mw.ustring.sub(stem,1,-3) .. pal[cons2] .. "ūs"
		end
		p[3] = p[1] .. "m"
		p[4] = p[2] .. "s"
		p[5] = p[3]
		p[7] = p[1]
	elseif (dk=="m1" or e1=="s" or e1=="š") then
		if e2=="ys" then stem = mw.ustring.sub(s[1],1,-3) else stem = mw.ustring.sub(s[1],1,-2) end
		s[2] = stem .. "a"
		s[3] = stem .. "am"
		s[4] = stem .. "u"
		s[5] = s[4]
		s[6] = stem .. "ā"
		s[7] = stem
		p[1] = stem .. "i"
		p[2] = stem .. "u"
		p[3] = stem .. "im"
		p[4] = stem .. "us"
		p[5] = p[3]
		p[6] = stem .. "ūs"
		p[7] = p[1]
	elseif (e1=="a") then
		stem = mw.ustring.sub(s[1],1,-2)
		cons = mw.ustring.sub(stem,-1)
		if mw.ustring.find("jļņ",cons,1,plain) then 
			if depal[cons] then
				s[2] = mw.ustring.sub(s[1],1,-3) .. depal[cons] .. "is, " .. stem .. cons .. "as" 
			else
				s[2] = stem .. "is, " .. stem .. "as"
			end
		else 
			s[2] = stem .. "ys, " .. stem .. "as" 
		end
		s[3] = stem .. "ai"
		s[4] = stem .. "u"
		s[5] = s[4]
		s[6] = stem .. "ā"
		s[7] = s[1]
		p[1] = s[2]
		p[2] = stem .. "u"
		p[3] = stem .. "om"
		p[4] = s[2]
		p[5] = p[3]
		p[6] = stem .. "uos"
		p[7] = p[1]
	elseif (e1=="e") then
		stem = mw.ustring.sub(s[1],1,-2)
		s[2] = stem .. "is, " .. stem .. "es"
		s[3] = stem .. "ei"
		s[4] = stem .. "i"
		s[5] = s[4]
		s[6] = stem .. "ē"
		s[7] = s[1]
		p[1] = s[2]
		p[3] = stem .. "em"
		p[4] = s[2]
		p[5] = p[3]
		p[6] = stem .. "ēs"
		p[7] = p[1]
		cons = mw.ustring.sub(stem,-1)
		cons2 = mw.ustring.sub(stem,-2)
		cons3 = mw.ustring.sub(stem,-3)
		if pal[cons] then
			p[2] = mw.ustring.sub(stem,1,-2) .. pal[cons] .. "u"
		end
		if pal[cons2] then
			p[2] = mw.ustring.sub(stem,1,-3) .. pal[cons2] .. "u"
		end
		if pal[cons3] then
			p[2] = mw.ustring.sub(stem,1,-4) .. pal[cons3] .. "u"
		end
	end

	local Sgdash = args["kSg"] and "&mdash;"
	local Pldash = args["kPl"] and "&mdash;"

	if t=="1" then 
		root:addClass('wikitable hintergrundfarbe2') 
		root:css('float','left')
	else
		root:addClass ('wikitable inflection-table float-right hintergrundfarbe2')
	end

	root:tag('tr')
			:css('background-color', '#F4F4F4')
			:tag('th')
				:wikitext('[[Hilfe:Kasus|Kasus]]')
			:tag('th')
				:wikitext('[[Hilfe:Singular|Singular]]')
			:tag('th')
				:wikitext('[[Hilfe:Plural|Plural]]')
		if (t=="1") then root:wikitext(makeTestRow('[[Hilfe:Nominativ|Nominativ]]',args["Nominativ Singular"],args["Nominativ Plural"],s[1],p[1])) 
		else root:wikitext(makeRow(
			'[[Hilfe:Nominativ|Nominativ]]',
			Sgdash or flexlink(args["Nominativ Singular"] or mw.title.getCurrentTitle().text or s[1]),
			Pldash or flexlink(args["Nominativ Plural"] or p[1])))
		end
		if (t=="1") then root:wikitext(makeTestRow('[[Hilfe:Genitiv|Genitiv]]',args["Genitiv Singular"],args["Genitiv Plural"],s[2],p[2])) 
		else root:wikitext(makeRow(
			'[[Hilfe:Genitiv|Genitiv]]',
			Sgdash or flexlink(args["Genitiv Singular"] or s[2]),
			Pldash or flexlink(args["Genitiv Plural"] or p[2])))
		end
		if (t=="1") then root:wikitext(makeTestRow('[[Hilfe:Dativ|Dativ]]',args["Dativ Singular"],args["Dativ Plural"],s[3],p[3])) 
		else root:wikitext(makeRow(
			'[[Hilfe:Dativ|Dativ]]',
			Sgdash or flexlink(args["Dativ Singular"] or s[3]),
			Pldash or flexlink(args["Dativ Plural"] or p[3])))
		end
		if (t=="1") then root:wikitext(makeTestRow('[[Hilfe:Akkusativ|Akkusativ]]',args["Akkusativ Singular"],args["Akkusativ Plural"],s[4],p[4])) 
		else root:wikitext(makeRow(
			'[[Hilfe:Akkusativ|Akkusativ]]',
			Sgdash or flexlink(args["Akkusativ Singular"] or s[4]),
			Pldash or flexlink(args["Akkusativ Plural"] or p[4])))
		end
		if (t=="1") then root:wikitext(makeTestRow('[[Hilfe:Instrumental|Instrumental]]',args["Instrumental Singular"],args["Instrumental Plural"],s[5],p[5])) 
		else root:wikitext(makeRow(
			'[[Hilfe:Instrumental|Instrumental]]',
			Sgdash or flexlink(args["Instrumental Singular"] or s[5]),
			Pldash or flexlink(args["Instrumental Plural"] or p[5])))
		end
		if (t=="1") then root:wikitext(makeTestRow('[[Hilfe:Lokativ|Lokativ]]',args["Lokativ Singular"],args["Lokativ Plural"],s[6],p[6])) 
		else root:wikitext(makeRow(
			'[[Hilfe:Lokativ|Lokativ]]',
			Sgdash or flexlink(args["Lokativ Singular"] or s[6]),
			Pldash or flexlink(args["Lokativ Plural"] or p[6])))
		end
		if (t=="1") then root:wikitext(makeTestRow('[[Hilfe:Vokativ|Vokativ]]',args["Vokativ Singular"],args["Vokativ Plural"],s[7],p[7])) 
		else root:wikitext(makeRow(
			'[[Hilfe:Vokativ|Vokativ]]',
			Sgdash or flexlink(args["Vokativ Singular"] or s[7]),
			Pldash or flexlink(args["Vokativ Plural"] or p[7])))
		end
	return tostring(root)
end


function flexlink(str)
  if (not str) then str="" end
  str = "[[" .. str .. "]]"
  str = mw.ustring.gsub(str,", ","]]<br />[[")
  str = mw.ustring.gsub(str,"%[%[%(","([[")
  str = mw.ustring.gsub(str,"%)%]%]","]])")
  return str
end

return flex