Module:User:Santi2222/fax-conj

local lang = require("Module:languages").getByCode("fax") local m_utilities = require("Module:utilities") local m_links = require("Module:links") local m_data = require("Module:User:Santi2222/fax-conj/data")

local match = mw.ustring.match local gmatch = mw.ustring.gmatch local gsub = mw.ustring.gsub

local export = {}

-- Dialects. Arbitrary order (alphabetical) local d = {["L"] = 1, ["M"] = 2, ["V"] = 3} local d_full = {["L"] = "Lagarteiru", ["M"] = "Mañegu", ["V"] = "Valverdeñu"}

-- Inflection functions

function export.show(frame) local parent_args = frame:getParent.args local dialects = parent_args[1] or nil local base = parent_args[2] or mw.title.getCurrentTitle.text --find the ending of the verb local infl_type = "" if base:match("[aei]lsi$") then infl_type = base:match("[aei]lsi$") elseif base:match("[aei]l$") then infl_type = base:match("[aei]l$") else if not m_data[base] then error("This word doesn't have a valid ending.") end end

local data = {forms = {}, categories = {}} data.head = base data.nocat = parent_args["nocat"] and true or false data.infl_type = infl_type data.prefix = parent_args.prefix or "" -- Generate the forms if m_data[base] then m_data[base](parent_args, data) else args = require("Module:parameters").process(parent_args, m_data[infl_type].params, true) m_data[infl_type](args, data) end data.info = m_links.full_link({lang = lang, alt = data.prefix .. data.head}, "term") --generate the table and add categories if not dialects then error("Please provide the dialects in which this verb is used.") elseif not dialects:match("^L?M?V?$") then error("Please provide the dialects in which this verb is used in the proper format.") else local tables = "" for dialect in gmatch(dialects, "%u") do			data.dialect = dialect tables = tables .. make_table(data) end return tables .. m_utilities.format_categories(data.categories, lang) end end

-- Make the table function make_table(data) local function repl(param) if param == "info" then return mw.getContentLanguage:ucfirst(data.info or "") end if param == "dialect" then return mw.getContentLanguage:ucfirst(d_full[data.dialect] or "") end if param == "alternation" then return mw.getContentLanguage:ucfirst(data.alternation or "") end local np = data.forms[param] local forms = np and (np["LMV"] and np[1] or np[d[data.dialect]]) or nil if not forms then return "&mdash;" end local ret = {} for key, subform in ipairs(forms) do table.insert(ret, m_links.full_link({lang = lang, term = data.prefix .. subform})) end return table.concat(ret, " ") end local wikicode = [=[ Conjugation of ]=]	return gsub(wikicode, "", repl) end

return export