Module:government: Difference between revisions

Jump to navigation Jump to search
Added auto decatting of accusative with verbs
No edit summary
(Added auto decatting of accusative with verbs)
(15 intermediate revisions by the same user not shown)
Line 7: Line 7:
-- COLOUR DATA
-- COLOUR DATA
local data = mw.loadData("Module:government/data")
local data = mw.loadData("Module:government/data")
local l_data = mw.loadData("Module:languages/data")


local function pluralize(word)
local function pluralize(word)
Line 18: Line 17:
end
end


function export.generate(frame)
function export.show(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local label = ""
local language, pos
local colour = ""
if mw.ustring.find(args[1], "^[a-z]+%s+[a-z]+$") then
language, pos = mw.ustring.match(args[1], "^([a-z]+)%s+([a-z]+)$")
if not args[1] then
language = m_languages.find_by_code(language)
error("First argument required")
pos = ( language ~= nil and (data["pos aliases"][pos] or pos) ) or nil
end
if data[args[1]] then
label = data[args[1]].label
colour = args[2] or data[args[1]].colour
else
else
label = args[1]
language = m_languages.find_by_code(args[1])
colour = args[2] or nil
pos = data["pos aliases"][args["pos"]] or args["pos"]
end
end
local to_Return = "["
if (language and args[2] == nil) or args[1] == nil then error("Entry parameter is missing") end
if language == nil and pos then error("The |pos parameter requires the language code to be specified in the first parameter") end
if args["prep"] then
to_Return = to_Return .. "+ <i>[[" .. args["prep"] .. "#" .. l_data[args["l"]].name .. "|" .. args["prep"] .. "]]</i> "
end
if colour then
to_Return = to_Return .. "<span style=\"background-color: #" .. colour .. ";\">+" .. label .. "</span>"
else
to_Return = to_Return .. "+" .. label
end
if args["t"] then
to_Return = to_Return .. " = " .. args["t"]
end
to_Return = to_Return .. "]"
if args["l"] and args["pos"] then
to_Return = to_Return .. "[[Category:" .. l_data[args["l"]].name .. " " .. pluralize(args["pos"]) .. " governing the " .. label .. "]]"
end
return to_Return
end
function export.show(frame)
local args = getArgs(frame)
local language = m_languages.get_by_code(args[1])
if args[2] == nil then error("Second parameter is missing") end
local show = "["
local show = "["
Line 71: Line 39:
local i = 2
local i = 2
if language == nil then i = 1 end
while args[i] do
while args[i] do
if i > 2 then
if #show > 1 then
append("; ''or'' ")
append("; ''or'' ")
end
end
Line 96: Line 66:
if conjunction == "/" then
if conjunction == "/" then
append(" ''or'' ")
append(" ''or'' ")
elseif conjunction == "+" then
elseif conjunction == "+" and not with_needed then
append(" ''and'' ")
append(" ''and'' ")
end
end
Line 103: Line 73:
temp = mw.ustring.sub(temp, 2)
temp = mw.ustring.sub(temp, 2)
elseif with_needed then
elseif with_needed then
append("''with'' ")
append(" ''with'' ")
with_needed = false
with_needed = false
end
end
else
else
local function glossary(form, colour)
local function glossary(form, colour)
form = mw.ustring.gsub(form, "^%*", "")
if mw.ustring.sub(form, 1, 1) == "_" then
if mw.ustring.sub(form, 1, 1) == "_" then
return "''" .. mw.ustring.sub(form, 2) .. "''"
return "''" .. mw.ustring.sub(form, 2) .. "''"
Line 127: Line 98:
end
end
local form, colour
local form, colour
if mw.ustring.find(temp, "^%([^%)]+%)%:") then -- for postpositions
form = mw.ustring.match(temp, "^%(([^%)]+)%)%:")
remove_temp("^%([^%)]+%)%:")
if mw.ustring.find(temp, "^%[[^%]]+%]") then
colour = mw.ustring.match(temp, "^%[([^%]]+)%]")
remove_temp("^%[[^%]]+%]")
end
temp_append("(" .. glossary(form, colour) .. " +) ")
end
if mw.ustring.find(temp, "^%:[^%(%<%[%+%/%:]+") then
if mw.ustring.find(temp, "^%:[^%(%<%[%+%/%:]+") then
if language == nil then error("A language code must be specified in the first parameter for the link function to work") end
temp_append("'''")
temp_append("'''")
while mw.ustring.find(temp, "^%:[^%(%<%[%+%/%:]+") do
while mw.ustring.find(temp, "^%:[^%(%<%[%+%/%:]+") do
local link = mw.ustring.match(temp, "^%:([^%(%<%[%+%/%:]+)")
local link = mw.ustring.match(temp, "^%:([^%(%<%[%+%/%:]+)")
local spacing = mw.ustring.match(link, "%s+$", "") or ""
local spacing = mw.ustring.match(link, "%s+$") or ""
link = mw.ustring.gsub(link, "%s+$", "")
link = mw.ustring.gsub(link, "%s+$", "")
temp_append(m_links.full_link{language = language, term = link} .. spacing)
temp_append(m_links.full_link{language = language, term = link} .. spacing)
Line 155: Line 136:
end
end
temp_append(glossary(form, colour))
temp_append(glossary(form, colour))
if args["pos"] then
if language and pos and data[form] then
if data[form] then form = data[form].label end
if not (data[form].label == "accusative" and pos == "verb") then
temp_append("[[Category:" .. language.name .. " " .. pluralize(args["pos"]) .. " governing the " .. form .. "]]")
temp_append("[[Category:" .. language.name .. " " .. pluralize(pos) .. " governing the " .. data[form].label .. "]]")
end
end
end
else
else
Line 176: Line 158:
remove_temp("^%<[^%>]+%>")
remove_temp("^%<[^%>]+%>")
end
end
append(q .. temp_main .. qq .. t)
append(q .. temp_main .. t .. qq)
end
end
end
end

Navigation menu