I gn a nén co di dzo-pådje /doc pol notule d’ esplikêyes. Clitchîz cial po l’ ahiver.
local p = {}
local builder = require("Module:Builder")
local r = require("Module:Riscrijhaedje");
local r_ = r.aclape_bodje_cawe -- alias
local trokes = {"prumire", "deujhinme", "troejhinme", "cwatrinme", "cénkinme"}
local voyale = "^[aâäåeéèêëiîoôuû]"
local croejhete = {}
local codjowas = {}

function p.candje_bodjes(t, bodjes, Y)
	for k,v in pairs(t) do
		if type(v) == "table" then
			t[k] = p.candje_bodjes(v, bodjes, Y)
		else
			local bodje, caw = nil
			bdjcaw = mw.text.split(v, "-", true)
			bodje = bdjcaw[1]
			if bdjcaw[2] ~= nil then
				caw = bdjcaw[2]
			end
			bodje = string.gsub(bodje, "([A-C])", function(AC) return bodjes[AC] end)
			if caw ~= nil then
				if Y ~= nil then
					caw = string.gsub(caw, "Y([1-3])", function(y) return Y[tonumber(y)] end)
				end
				t[k] = r_(bodje, caw)
			else
				t[k] = bodje
			end
			
		end
	end
	return t
end

function html_tavlea_codjowa_hardeye(codjowas)
	local loyens = {}
	if type(codjowas) == "string" then
		codjowas = {codjowas}
	end
	if type(codjowas) == "table" then
		for i,c in ipairs(codjowas) do
			cl = string.gsub(c, "[()]", "") -- v(i)ni > vini
			table.insert(loyens,"[["..cl.."#Codjowa|"..c.."]]")
		end
	end
	return table.concat(loyens, ", ")
end

-- pwaire : tins simpe + ripassé
function html_tavlea_tins_pwaire(simpe, compoze)
	local div = mw.html.create("div")
	          :attr("class", "codjowaedje-tins-pwaire")
	          :node(simpe)
	          :node(compoze)
	return div
end

-- prezintrece, erirece, ...
function html_tavlea_tins(tite, codjowas, hardeye)
	if hardeye ~= false then hardeye = true end
	local div_title = mw.html.create("div")
	          :attr("class", "codjowaedje-tins-title")
	          :wikitext(dobe)
	          :wikitext(tite)
	local div_tins = mw.html.create("div")
	          :attr("class", "codjowaedje-tins")
	          :node(div_title)
	local div_codjowas = mw.html.create("div")
	          :attr("class", "codjowaedje-tins-codjowas")
	if codjowas ~=nil then
		if type(codjowas[1]) == "string" then codjowas = {codjowas} end
		for i, v in ipairs( codjowas ) do
		    prono = v[1] ; codjowa = v[2]
		    if hardeye then codjowa = html_tavlea_codjowa_hardeye(codjowa) end
		    local span_prono = mw.html.create("span")
		                     :attr("class", "codjowaedje-prono")
		                     :wikitext(prono)
		    local span_codjowa = mw.html.create("span")
		                       :attr("class", "codjowaedje-codjowa")
		                       :wikitext(codjowa)
		    local div_codjowa = mw.html.create("div")
		                      :attr("class", "codjowaedje-codjowa-"..i)
		                      :node(span_prono)
		                      :node(span_codjowa)
		    div_codjowas:node(div_codjowa)
		end
	else
		div_codjowas:attr("class", "codjowaedje-tins-codjowas-vude")
		            :wikitext("nén eployî")
	end
	div_tins:node(div_codjowas)
	return div_tins
end

-- indicatif, suddjontif,...
function html_tavlea_mode_tite(tite)
	local div = mw.html.create("div")
	          :attr("class", "codjowaedje-mode-tite")
	          :wikitext(tite)
	return div
end

function p.html_tavlea()
	local html = mw.html.create("div")
	           :attr("class", "codjowaedje")
	local div_copete = mw.html.create("div")
	                 :attr("class", "codjowaedje-copete")
	local div_tite = mw.html.create("div")
	               :attr("class", "codjowaedje-tite")
	               :wikitext("Codjowaedje do viebe ")
	if type(codjowas.INF) == "table" then
		for k,v in ipairs(codjowas.INF) do
			if k > 1 then
				div_tite:wikitext(", ")
			end
			div_tite:wikitext("<em>[["..v.."#Viebe|"..v.."]]</em>")
		end
	else
		div_tite:wikitext("<em>[["..codjowas.INF.."#Viebe|"..codjowas.INF.."]]</em>")	
	end
	local div_troke = mw.html.create("div")
	                :attr("class", "codjowaedje-troke")
	                :wikitext("Croejhete [[Rawete:Codjowaedje do walon/"..croejhete.ID.."| "..croejhete.ID.."]], ")
	                :wikitext("viebe del [[Rawete:Codjowaedje do walon/"..croejhete.ID.."/"..trokes[codjowas.troke].." troke|"..trokes[codjowas.troke].." troke]]")
	
	div_copete:node(div_tite)
	          :node(div_troke)
	          
	if codjowas.rile ~= nil then             
		local div_rile = mw.html.create("div")
	                :attr("class", "codjowaedje-rile")
	                :wikitext("(avou l’ "..codjowas.rile..")")
	    div_copete:node(div_rile)
	end
	
	html:node(div_copete)
	    :node(html_tavlea_mode_tite("PÅRTICIPES"))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("PREZINTRECE", codjowas.PP),
	        	html_tavlea_tins("ERIRECE", {{nil, codjowas.PE},{'<i>f.</i>', codjowas.PEf}})
	    ))
	    :node(html_tavlea_mode_tite("INDICATIF"))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("PREZINTRECE", codjowas.IP),
	        	html_tavlea_tins("RIPASSÉ PREZINT", codjowas.R.IP, false)
	    ))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("ERIRECE DURANT", codjowas.DIE),
	        	html_tavlea_tins("RIPASSÉ ERIRECE DURANT", codjowas.R.DIE, false)
	    ))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("ERIRECE", codjowas.IE),
	        	html_tavlea_tins("RIPASSÉ ERIRECE", codjowas.R.IE, false)
	    ))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("FUTUR", codjowas.IF),
	        	html_tavlea_tins("RIPASSÉ FUTURRECE", codjowas.R.IF, false)
	    ))
	    :node(html_tavlea_mode_tite("SUDDJONCTIF"))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("PREZINTRECE", codjowas.SP),
	        	html_tavlea_tins("ERIRECE", codjowas.R.SP, false)
	    ))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("ERIRECE DURANT", codjowas.DSE),
	        	html_tavlea_tins("RIPASSÉ ERIRECE DURANT", codjowas.R.DSE, false)
	    ))
	    :node(html_tavlea_mode_tite("CONDICIONEU"))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("PREZINTRECE", codjowas.C),
	        	html_tavlea_tins("ERIRECE", codjowas.R.C, false)
	    ))
	    :node(html_tavlea_mode_tite("KIMANDEU"))
	    :node(html_tavlea_tins_pwaire(
	    		html_tavlea_tins("PREZINTRECE", codjowas.K),
	        	html_tavlea_tins("ERIRECE", codjowas.R.K, false)
	    ))
	    
	return html
end

function p.radjoute_prono(t,c,d,sdj)
	if type(c) == "table"  and d == nil then
		for k,v in ipairs(c) do
			p.radjoute_prono(t,v,k,sdj)
		end
	elseif t~= "R" and t ~= "PE" and t ~= "PEf" and t ~= "INF" then
		if type(c) == "table" then ct = c[1] else ct = c end
		local sd = 1 ; if ct ~= nil and mw.ustring.find(ct, voyale) ~= nil then sd = 2 end
		if t == "K" then
			prono = ""
			prono_R = ""
		elseif t == "PP" then
			prono = tostring(croejhete.djerondif[sd])
			prono_R = ""
		elseif d ~= nil then
			if sdj and croejhete.pronos[d][4] ~=nil then 
				if sd == 2 then sd = 5 else sd = 4 end 
			end
			prono = tostring(croejhete.pronos[d][sd])
			prono_R = tostring(croejhete.pronos[d][2])
			if t == "SP" or t == "DSE" then
				prono = table.concat({tostring(croejhete.ki[2]), prono}, " ")
				prono_R = table.concat({tostring(croejhete.ki[2]), prono_R}, " ")
			end
		end
		
		if type(codjowas[t]) == "table" then
			if codjowas[t][d] == "" then
				codjowas[t][d] = {nil, nil}
				codjowas["R"][t][d] = {nil, nil} 
			else
				codjowas[t][d] = {prono, c} -- {dji,boute}
				if type(croejhete.aveur[t][d]) == "table" then 
					aveur = table.concat(croejhete.aveur[t][d], ",<br/>")
				else
					aveur = tostring(croejhete.aveur[t][d]) 
				end
				local pe = codjowas.PE
				if type(codjowas.PE) == "table" then pe = codjowas.PE[1] end
				pe = string.gsub(pe, "%(.+%)", "") -- v(i)nou > vnou 
				codjowas["R"][t][d] = {table.concat({prono_R, aveur}, " "), pe} -- {dj’a,bouté}
			end
		else
			codjowas[t] = {prono, c} -- {e,boutant}
		end
	end
end

function p.codjowoe(troke, bodjes, args)
	local rile = nil
	
	if bodjes == nil then 
		codjowas = p.novea_tavlea_codjowas()
	else
		-- våt po totès croejhetes (sins conter les vîs sistinmes : E203 evnd) ?
		if mw.ustring.find(bodjes.A , "k$") ~= nil then
			rile = "[[Rawete:Rîle do scrijhaedje do son K|rîle do scrijhaedje do son K]]"
		elseif mw.ustring.find(bodjes.A , "g$") ~= nil then
			rile = "[[Rawete:Rîle do scrijhaedje do son GU|rîle do scrijhaedje do son GU]]"
		elseif mw.ustring.find(bodjes.A , "ss$") ~= nil then
			rile = "[[Rawete:Rîle do scrijhaedje do son S|rîle do scrijhaedje do son S]]"
		end
		codjowas = croejhete.tavlea_codjowas(troke, bodjes.A, bodjes.B, bodjes.C, bodjes.X)
	end
	
	p.spotche_codjowas(args)
	
	if args.mode ~= nil and (args.mode == "sins djins" or args.mode == "sins djins pluriyal") then
		sdj = true
		for t, v in pairs( codjowas ) do
	    	if type(v) == "table" then
	    		for dj, c in ipairs( v ) do
	    			if t~= "K" then 
	    			   if (args.mode == "sins djins pluriyal" and dj ~= 3 and dj ~= 6) or 
	    			      (args.mode == "sins djins" and dj ~= 3) then 
	    					codjowas[t][dj] = ""
	    				end
	    			elseif t== "K" and dj ~= 1 then
	    				codjowas[t][dj] = ""
	    			end
	    		end
	    	end
	    end
	end
	
	codjowas["R"] = {}
    for t, v in pairs( codjowas ) do
    	codjowas["R"][t] = {}
    	p.radjoute_prono(t,v,nil,sdj)
    end
    
    codjowas.troke = troke
    codjowas.rile = rile
    
	return codjowas
end

function p.novea_tavlea_codjowas()
	codjowas["R"] = {}
	for t,v in pairs(croejhete.codjowas[1]) do
		if type(v) == "table" then
			codjowas[t] = nil
			codjowas["R"][t] = nil
		else
			codjowas[t] = ""
			codjowas["R"][t] = ""
		end
	end
	codjowas["troke"] = 1
	return codjowas
end

function p.spotche_codjowas(args)
	for k,v in pairs(args) do
		-- IP1s, IP1s-2
		if string.find(k , "^[A-Z]+[1-3][sp]$") ~= nil or
		   string.find(k , "^[A-Z]+[1-3][sp][.-][1-5]$") ~= nil then
			k = string.gsub(k, "([A-Z]+)([1-3])([sp])[.-]?([1-5]?)", function(t,dj,sp,l) return t.."-"..dj.."-"..sp.."-"..l end) 	
			k = mw.text.split(k, "-", true)
			if k[1] ~= nil and k[2] ~= nil then 
				if k[3] ~= nil and k[3] =="p" then 
					if k[1] == "K" then
						k[2] = 1+k[2] -- K1pl=(K)1+1=2
					else
						k[2] = 3+k[2] -- IP1pl=(IP)1+3=4
					end
				end 
				if codjowas[k[1]] == nil then
					codjowas[k[1]] = {}
				end
				if k[4] ~= nil and k[4] ~= "" then
					if codjowas[k[1]][tonumber(k[2])] == nil then
						codjowas[k[1]][tonumber(k[2])] = {}
					elseif type(codjowas[k[1]][tonumber(k[2])]) == "string" then
						codjowas[k[1]][tonumber(k[2])] = {codjowas[k[1]][tonumber(k[2])]} -- string > array
					end
					table.insert(codjowas[k[1]][tonumber(k[2])], tonumber(k[4]), v)
				else
					if type(codjowas[k[1]][tonumber(k[2])]) == "table" then
						table.insert(codjowas[k[1]][tonumber(k[2])], 1, v)
					else
						codjowas[k[1]][tonumber(k[2])] = v
					end
				end
			end
		-- PP, PP-2, INF, INF-2
		elseif string.find(k , "^[A-Z]+f?[.-][1-5]$") ~= nil then
			k = string.gsub(k, "([A-Z]+f?)[.-]([1-5])", function(t,l) return t.."-"..l end) 	
			k = mw.text.split(k, "-", true)
			if type(codjowas[k[1]]) == "string" then
				if codjowas[k[1]] == "" then
					if k[1] == "INF" or k[1] == "PE" or k[1] == "PEf" then
						codjowas[k[1]] = {}
					else
						codjowas[k[1]] = {[1]={}}
					end
				else
					if k[1] == "INF" or k[1] == "PE" or k[1] == "PEf" then
						codjowas[k[1]] = {codjowas[k[1]]}
					else
						codjowas[k[1]] = {[1]={codjowas[k[1]]}}
					end
				end
			end
			if k[1] == "INF" or k[1] == "PE" or k[1] == "PEf" then
				table.insert(codjowas[k[1]], v)
			else
				table.insert(codjowas[k[1]][1], v)
			end
		elseif k ~= "A" and k ~= "B" and k ~= "C" then
			if codjowas[k] ~= nil then
				if k == "troke" then v=tonumber(v) end
				if type(codjowas[k]) == "table" then
					if k == "INF" or k == "PE" or k[1] == "PEf" then
						table.insert(codjowas[k], v)
					else
						table.insert(codjowas[k][1], 1, v) -- PP
					end	
				else
					codjowas[k] = v
				end
			end	
		end
	end
end

function p.init(frame)
	local args = frame.args
	local croejhete_id = "RIF" -- sôre di croejhete CO4,CC1,S0
	local troke = nil -- troke di viebe 1-5 (sorlon les croejhetes)
	local A, B, C = nil -- bodjes
	local X = mw.title.getCurrentTitle().subpageText
	
	if args.croejhete ~= nil and args.croejhete ~= "" then 
		croejhete_id = args.croejhete
	end
	
	if args.troke ~= nil and args.troke ~= "" then 
		troke = tonumber(args.troke)
	end
	
	local fitchi_croejhete = mw.title.new( "Codjowoe/"..croejhete_id, "Module" )
	if fitchi_croejhete.exists then
		croejhete = require(fitchi_croejhete.fullText);
		croejhete.ID = croejhete_id
	else
		builder.error("li croejhete <code>"..croejhete_id.."</code> n’ est nén ricnoxhowe")
	end
	
	if args.troke == nil then
		builder.error("li troke do viebe n’ est nén dné")
	elseif type(troke) ~= "number" then 
		builder.error("li troke do viebe <code>"..troke.."</code> n’ est nén on chife")
	else
		if args.A ~= nil and args.A ~= "" then
			A = args.A ; B = A ; C = A 
			if args.B ~= nil and args.B ~= "" then B = args.B end
			if args.C ~= nil and args.C ~= "" then C = args.C end
			if args.X ~= nil and args.X ~= "" then X = args.X end
			codjowas = p.codjowoe(troke, {A=A,B=B,C=C,X=X}, args)
		else
			codjowas = p.codjowoe(troke, nil, args)
		end
		
		if codjowas ~= false then
			builder.add_content(p.html_tavlea())
		end
	end
	
	return  builder.get_content()
end

return p