Module:form of: Difference between revisions

From Laenkea
Jump to navigation Jump to search
mNo edit summary
Tag: Manual revert
mNo edit summary
Line 9: Line 9:
if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end
if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end
local l = m_data.labels[inflection]
local l = m_data.labels[inflection]
if i > 1 and inflection ~= "/" then
if i > 1 then
table.insert(out, " ")
table.insert(out, inflection == "/" and "" or " ")
end
end
if l then
if l then
Line 23: Line 23:
end
end
if inflections[i+1] and inflection ~= "/" then
if inflections[i+1] and inflection ~= "/" then
table.insert(out, " ")
table.insert(out, inflection == "/" and "" or " ")
end
end
end
end

Revision as of 05:04, 10 December 2023

local export = {}

local m_links = require("Module:links")
local m_data = mw.loadData("Module:form of/data")

local function make_labels(inflections)
	local out = {}
	for i, inflection in ipairs(inflections) do
		if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end
		local l = m_data.labels[inflection]
		if i > 1 then
			table.insert(out, inflection == "/" and "" or " ")	
		end
		if l then
			local text = l.label or inflection
			if l.glossary then
				table.insert(out, "[[Appendix:Glossary#" .. (type(l.glossary) == "string" and l.glossary or text) .. "|" .. text .. "]]")
			else
				table.insert(out, text)
			end
		else
			table.insert(out, inflection)
		end
		if inflections[i+1] and inflection ~= "/" then
			table.insert(out, inflection == "/" and "" or " ")
		end
	end
	return table.concat(out)
end

function export.make_form_of(data)
	local label
	local link = m_links.full_link(data, "term")
	if data.inflection then
		label = make_labels(data.inflection)
	else
		label = data.form or "alternative form"
	end
	return '<span class="form-of">' .. label .. ' of ' .. link .. '</span>'
end

function export.list_form(data)
	local label
	if data.inflection then
		label = make_labels(data.inflection)
	else
		label = data.form or "alternative form"
	end
	return '<span class="form-of">' .. label .. '</span>'
end

return export