Module:links

From Laenkea
Revision as of 18:43, 5 August 2023 by Maria (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:links/documentation

local export = {}

local function make_list(frame, link_type)
	if link_type ~= "mention" and link_type ~= "list" then
		error("Link type must be specified")
	end
	local language_code = frame.args[1]
	local word = frame.args[2]
	local display = frame.args[3] or frame.args["display"] or frame.args["d"]
	local text = frame.args[4] or frame.args["text"] or frame.args["t"]
	local pos = frame.args["pos"]
	local language = require("Module:languages").get_by_code(language_code)
	local link = ""
	if link_type == "mention" then
		if type(language.link) == "string" then
			link = link .. "[[" .. language.link .. "|" .. language.name .. "]] "
		else
			link = link .. language.name .. " "
		end
	end
	local link_format = (link_type == "mention" and "''") or ""
	local link_proto = (language.proto and ("Appendix:" .. string.gsub(language.name, " ", "_") .. "/")) or ""
	local link_display_proto = (language.proto and "*") or ""
	local link_display = display or word
	link = link .. link_format .. "[[" .. link_proto .. word .. "#" .. string.gsub(language.name, " ", "_") .. "|" .. link_display_proto .. link_display .. "]]" .. link_format
	if type(text) == "string" or type(pos) == "string" then
		link = link .. " ("
		if type(text) == "string" then
			link = link .. "“" .. text .. "”" .. ((type(pos) == "string" and ", ") or "")
		end
		if type(pos) == "string" then
			link = link .. pos
		end
		link = link .. ")"
	end
	return link
end

function export.list(frame)
	frame = frame:getParent() or frame
	return make_list(frame, "list")
end

function export.mention(frame)
	frame = frame:getParent() or frame
	return make_list(frame, "mention")
end

return export