Module:government: Difference between revisions

From Laenkea
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 2: Line 2:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs


local m_languages = require('Module:languages')
local m_links = require('Module:links')


-- COLOUR DATA
-- COLOUR DATA
Line 56: Line 58:
return to_Return
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 function append(text)
show = show .. text
end
local i = 2
while args[i] do
if i > 2 then
append("; ''or'' ")
end
local temp = args[i]
if mw.ustring.sub(temp, 1, 1) == "&" then
temp = mw.ustring.sub(temp, 2)
else
append("''with'' ")
end
while #temp > 0 do
mw.log(temp)
-- case<t>
-- :prep(case)<t>
-- &label<t>
local function remove_temp(regex)
temp = mw.ustring.gsub(temp, regex, "")
end
if mw.ustring.find(temp, "^%s*%/%s*") then
append(" ''or'' ")
remove_temp("^%s*%/%s*")
elseif mw.ustring.find(temp, "^%s*%+%s*") then
append(" ''and'' ")
remove_temp("^%s*%+%s*")
else
local function glossary(form, colour)
if data[form] then
form = data[form].label
if colour == nil then colour = data[form].colour end
end
local to_Return = "''[[Appendix:Glossary#" .. form .. "|" .. form .. "]]''"
if colour then
to_Return = "<span style=\"background-color: #" .. colour .. ";\">" .. to_Return .. "</span>"
end
return to_Return
end
local form, colour
if mw.ustring.find(temp, "^%:[^%(%<%[%+%/]+") then
local link = mw.ustring.match(temp, "^%:([^%(%<%[%+%/]+)")
append("'''" .. m_links.full_link{language = language, term = link} .. "'''")
remove_temp("^%:[^%(%<%[%+%/]+")
if mw.ustring.find(temp, "^%([^%)]+%)") then
form = mw.ustring.match(temp, "^%(([^%)]+)%)")
remove_temp("^%([^%)]+%)")
if mw.ustring.find(temp, "^%[[^%]]+%]") then
colour = mw.ustring.match(temp, "^%[([^%]]+)%]")
remove_temp("^%[[^%]]+%]")
end
append(" (+ " .. glossary(form, colour) .. ")")
end
else
form = mw.ustring.match(temp, "^([^%(%<%[%+%/]+)")
remove_temp("^([^%(%<%[%+%/]+)")
if mw.ustring.find(temp, "^%[[^%]]+%]") then
colour = mw.ustring.match(temp, "^%[([^%]]+)%]")
remove_temp("^%[[^%]]+%]")
end
append(glossary(form, colour))
if args["pos"] then
if data[form] then form = data[form].label end
append("[[Category:" .. language.name .. " " .. pluralize(args["pos"]) .. " governing the " .. form .. "]]")
end
end
end
end
i = i + 1
end
append("]")
return show
end
end


Line 63: Line 154:
Debug console test string:
Debug console test string:
=p.generate(mw.getCurrentFrame():newChild{title="whatever",args={"accusative"}})
=p.generate(mw.getCurrentFrame():newChild{title="whatever",args={"accusative"}})
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}})
]]
]]

Revision as of 21:19, 3 August 2024

See {{with}}. To add to the recognised argument list, edit Module:government/data.


local export = {}
local getArgs = require('Module:Arguments').getArgs

local m_languages = require('Module:languages')
local m_links = require('Module:links')

-- COLOUR DATA
local data = mw.loadData("Module:government/data")
local l_data = mw.loadData("Module:languages/data")

local function pluralize(word)
	local ending = mw.ustring.sub(word, -1)
	if ending == "h" and mw.ustring.sub(word, -2, -1) == "s" then ending = "sh" end
	if ending == "s" or ending == "z" or ending == "x" or ending == "sh" then
		return word .. "es"
	end
	return word .. "s"
end

function export.generate(frame)
	local args = getArgs(frame)
	local label = ""
	local colour = ""
	
	if not args[1] then
		error("First argument required")	
	end
	
	if data[args[1]] then
		label = data[args[1]].label
		colour = args[2] or data[args[1]].colour
	else
		label = args[1]
		colour = args[2] or nil
	end
	
	local to_Return = "["
	
	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 function append(text)
		show = show .. text	
	end
	
	local i = 2
	
	while args[i] do
		if i > 2 then
			append("; ''or'' ")
		end
		
		local temp = args[i]
		
		if mw.ustring.sub(temp, 1, 1) == "&" then
			temp = mw.ustring.sub(temp, 2)
		else
			append("''with'' ")
		end
		
		while #temp > 0 do
			mw.log(temp)
			-- case<t>
			-- :prep(case)<t>
			-- &label<t>
			local function remove_temp(regex)
				temp = mw.ustring.gsub(temp, regex, "")
			end
			if mw.ustring.find(temp, "^%s*%/%s*") then
				append(" ''or'' ")
				remove_temp("^%s*%/%s*")
			elseif mw.ustring.find(temp, "^%s*%+%s*") then
				append(" ''and'' ")
				remove_temp("^%s*%+%s*")
			else
				local function glossary(form, colour)
					if data[form] then
						form = data[form].label
						if colour == nil then colour = data[form].colour end
					end
					local to_Return = "''[[Appendix:Glossary#" .. form .. "|" .. form .. "]]''"
					if colour then
						to_Return = "<span style=\"background-color: #" .. colour .. ";\">" .. to_Return .. "</span>"
					end
					return to_Return
				end
				local form, colour
				if mw.ustring.find(temp, "^%:[^%(%<%[%+%/]+") then
					local link = mw.ustring.match(temp, "^%:([^%(%<%[%+%/]+)")
					append("'''" .. m_links.full_link{language = language, term = link} .. "'''")
					remove_temp("^%:[^%(%<%[%+%/]+")
					if mw.ustring.find(temp, "^%([^%)]+%)") then
						form = mw.ustring.match(temp, "^%(([^%)]+)%)")
						remove_temp("^%([^%)]+%)")
						if mw.ustring.find(temp, "^%[[^%]]+%]") then
							colour = mw.ustring.match(temp, "^%[([^%]]+)%]")
							remove_temp("^%[[^%]]+%]")
						end
						append(" (+ " .. glossary(form, colour) .. ")")
					end
				else
					form = mw.ustring.match(temp, "^([^%(%<%[%+%/]+)")
					remove_temp("^([^%(%<%[%+%/]+)")
					if mw.ustring.find(temp, "^%[[^%]]+%]") then
						colour = mw.ustring.match(temp, "^%[([^%]]+)%]")
						remove_temp("^%[[^%]]+%]")
					end
					append(glossary(form, colour))
					if args["pos"] then
						if data[form] then form = data[form].label end
						append("[[Category:" .. language.name .. " " .. pluralize(args["pos"]) .. " governing the " .. form .. "]]")
					end
				end
			end
		end
	
		i = i + 1	
	end
	
	append("]")
	
	return show
end

return export

--[[
Debug console test string:
=p.generate(mw.getCurrentFrame():newChild{title="whatever",args={"accusative"}})
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}})
]]