Module:links: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local export = {}
local export = {}


function export.make_link(args)
function export.language_link(data)
if args["link_type"] ~= "mention" and args["link_type"] ~= "list" then
if not data.term then
error("Link type must be specified")
error("language link data must contain term")
end
end
if not args["code"]  then
local link = "[[" .. data.term
error("Language code must be specified")
if data.language then
link = link .. "#" .. data.language.code
end
end
local word = args["word"]
return link .. "|" .. data.alt or data.term .. "]]"
local display = args["display"]
local text = args["text"]
local pos = args["pos"]
local noname = args["noname"]
local language = require("Module:languages").get_by_code(args["code"])
local link = ""
if args["link_type"] == "mention" and (not noname) then
if type(language.link) == "string" then
link = link .. "[[" .. language.link .. "|" .. language.name .. "]] "
else
link = link .. language.name .. " "
end
end
local link_format = (args["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
end


function export.make_list_link(args)
function export.link_extras(data)
args["link_type"] = "list"
if not (data.pos or data.gloss) then return nil end
return export.make_link(args)
local out = {}
if data.gloss then table.insert(out, '“' .. data.gloss .. '”') end
if data.pos then table.insert(out, data.pos) end
return table.concat(out)
end
end


function export.make_mention_link(args)
function export.full_link(data, face)
args["link_type"] = "mention"
local link = export.language_link(data)
return export.make_link(args, "mention")
if face and face ~= "" then
end
link = require("Module:formatting").wrap_face(link, data.language, face)
 
end
local function make_from_frame(frame, link_type)
local extras = export.link_extras(data)
local args = (frame:getParent() and frame:getParent().args) or frame.args
if extras then
return export.make_link{
extras = " (" .. extras .. ")"
["link_type"] = link_type,
end
["code"] = args[1],
local prefix
["word"] = args[2],
if data.language and data.showlanguage then
["display"] = args[3] or args["d"] or args["display"],
prefix = "[[" .. language.link .. "|" .. language.name .. "]] "
["text"] = args[4] or args["t"] or args["text"],
end
["pos"] = args["pos"],
return (prefix or "") .. link .. (extras or "")
["noname"] = args["noname"]
}
end
 
function export.list(frame)
return make_from_frame(frame, "list")
end
 
function export.mention(frame)
return make_from_frame(frame, "mention")
end
end


return export
return export

Revision as of 13:59, 6 August 2023

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

local export = {}

function export.language_link(data)
	if not data.term then
		error("language link data must contain term")
	end
	local link = "[[" .. data.term
	if data.language then
		link = link .. "#" .. data.language.code
	end
	return link .. "|" .. data.alt or data.term .. "]]"
end

function export.link_extras(data)
	if not (data.pos or data.gloss) then return nil end
	local out = {}
	if data.gloss then table.insert(out, '“' .. data.gloss .. '”') end
	if data.pos then table.insert(out, data.pos) end
	return table.concat(out)
end

function export.full_link(data, face)
	local link = export.language_link(data)
	if face and face ~= "" then
		link = require("Module:formatting").wrap_face(link, data.language, face)
	end
	local extras = export.link_extras(data)
	if extras then
		extras = " (" .. extras .. ")"
	end
	local prefix
	if data.language and data.showlanguage then
		prefix = "[[" .. language.link .. "|" .. language.name .. "]] "
	end
	return (prefix or "") .. link .. (extras or "")
end

return export