Module:indtr

From Wiktionary, the free dictionary
Jump to navigation Jump to search


local m_lb = require("Module:labels")
local export = {}

function export.show(frame)
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().text

	if (args[1] == nil and mw.title.getCurrentTitle().nsText == "Template") then
		args[1] = "und"
	end
	
	local lang = require("Module:languages").getByCode(args[1], 1)
	local nocat = args["nocat"] ~= nil
	local sort_key = args["sort"]
	local term_mode = (frame.args["term"]) ~= nil
	local labels = get_labels(args, require("Module:languages").getByCode(args[1]):getCanonicalName())
	
	return m_lb.show_labels {
		labels = labels,
		lang = lang,
		sort = sort_key,
		nocat = nocat,
		mode = term_mode and "term-label" or nil,
	}
end


function get_labels(args, langname)
	local labels = {}
	local indtr = ""
	local i = 2
	local q = nil
	local first = true
	local andwith = false
	
	if (args["intr"] ~= nil) then 
		indtr = indtr .. "[[Appendix:Glossary#intransitive|intransitive]], or "
	end
	
	
	while (args[i] ~= nil) do
	
		if (mw.ustring.sub(args[i], 0, 1) == ".") then
			table.insert(labels, mw.ustring.sub(args[i], 2));
		elseif (args[i] == ";") then
			andwith = true
			if (args[("qual" .. (i-1))] == nil or args[("qual" .. (i-1))] == "") then
				indtr = indtr .. " and with "
			else
				indtr = indtr .. " and " .. args[("qual" .. (i-1))] .. " with "
			end
		else
			if (first == false) then
				if (andwith == true) then
					andwith = false
				else
				    indtr = indtr .. " or "
				end
			else
				if (args["cop"] ~= nil and args["ditr"] ~= nil) then
					indtr = indtr .. "[[Appendix:Glossary#ditransitive|ditransitive]], [[Appendix:Glossary#copulative|copulative]] with "
				elseif (args["cop"] ~= nil) then
					indtr = indtr .. "[[Appendix:Glossary#copulative|copulative}} with "
				elseif (args["ditr"] ~= nil) then
					indtr = indtr .. "[[Appendix:Glossary#ditransitive|ditransitive]], with the indirect object taking "
				elseif (args["aux"] ~= nil) then
					indtr = indtr .. "[[Appendix:Glossary#auxiliary|auxiliary]] with "
				else
					indtr = indtr .. "[[Appendix:Glossary#transitive|transitive]] with "
				end
				first = false
			end
			
			if (mw.ustring.sub(args[i], 0, 1) == "-") then
				indtr = indtr ..  mw.ustring.sub(args[i], 2);
			else
				indtr = indtr .. "'''''[[" .. args[i] .. "#" .. langname .. "|" .. args[i] .. "]]'''''"
			end
			indtr = indtr .. qualifier(args[("qual" .. (i-1))])
		end
		i = i + 1
	end
	
	if (args["direct"] ~= nil) then 
		if (args["ditr"] ~= nil) then
			indtr = indtr .. " or no preposition"
		else
			indtr = indtr .. " or with no preposition"
		end
		indtr = indtr .. qualifier(args["qualdirect"])
	end
	
	if (args["aux"] ~= nil) then
		indtr = indtr .. " and a verb in the " .. args["aux"]
	elseif (args["cop"] ~= nil and args["ditr"] ~= nil) then
		indtr = indtr .. " for the second object"
	end
	
	table.insert(labels, indtr)
	return labels

end


function qualifier(text)
	if (text == nil or text == "") then return "" end
	return '&nbsp;<span class="ib-brac"><span class="qualifier-brac">(</span></span><span class="ib-content"><span class="qualifier-content">' .. text ..
'</span></span><span class="ib-brac"><span class="qualifier-brac">)</span></span>'
end

return export