Module:links: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
 
(47 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local export = {}
local export = {}


local function make_list(frame, link_type)
function export.language_link(data)
if link_type ~= "mention" and link_type ~= "list" then
if not data.term then
error("Link type must be specified")
error("language link data must contain term")
end
end
local language_code = frame.args[1]
local link = data.term
local word = frame.args[2]
local alt = data.alt or data.term
local display = frame.args[3] or frame.args["display"] or frame.args["d"]
local anchor = data.anchor
local text = frame.args[4] or frame.args["text"] or frame.args["t"]
local pos = frame.args["pos"]
local plaenk_alt = mw.loadData("Module:lnk-pro-morph/data").alt
local language = require("Module:languages").get_by_code(language_code)
local link = ""
if data.language then
if link_type == "mention" then
if type(language.link) == "string" then
if data.language.code == "lnk-pro" and plaenk_alt[link] then link = plaenk_alt[link] end
link = link .. "[[" .. language.link .. "|" .. language.name .. "]] "
if data.hypo then alt = "**" .. alt end
if data.language.proto then
if not data.nostar and not data.hypo then alt = "*" .. alt end -- * is an asterisk but sometimes the asterisk gets mistaken for wiki formatting
link = "Appendix:" .. data.language.name .. "/" .. data.term
if anchor then link = link .. "#" .. data.language.name .. anchor end
else
else
link = link .. language.name .. " "
local jump = data.language.name
if anchor then jump = data.language.name .. anchor end
link = link .. "#" .. string.gsub(jump, " ", "_")
end
end
end
end
local link_format = (link_type == "mention" and "''") or ""
local link_display = display or word
local term = mw.ustring.match(mw.ustring.gsub(link, " ", " "),"([^%#]+)")
link = link .. link_format .. "[[" .. word .. "#" .. string.gsub(language.name, " ", "_") .. "|" .. link_display .. "]]" .. link_format
if type(text) == "string" or type(pos) == "string" then
if term == mw.title.getCurrentTitle().text and not data.nobold then
link = link .. " ("
return "<b>" .. alt .. "</b>"
if type(text) == "string" then
elseif mw.ustring.match(term, "^[%?%-–—]+$") or mw.ustring.match(term, ":[%?%-–—]+$") or data.nolink then
link = link .. "" .. text .. "" .. ((type(pos) == "string" and ", ") or "")
return alt
end
else
if type(pos) == "string" then
return "[[" .. link .. "|" .. alt .. "]]"
link = link .. pos
end
link = link .. ")"
end
end
return link
end
end


function export.list(frame)
function export.link_extras(data)
frame = frame:getParent() or frame
if not (data.pos or data.gloss) then return nil end
return make_list(frame, "list")
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.mention(frame)
function export.full_link(data, face)
frame = frame:getParent() or frame
local link = export.language_link(data)
return make_list(frame, "mention")
link = require("Module:formatting").wrap_face(link, data.language, face or "nil")
local extras = export.link_extras(data)
if extras then
extras = " (" .. extras .. ")"
end
local prefix
if data.language and data.showlanguage then
prefix = "[[" .. data.language.link .. "|" .. data.language.name .. "]] "
end
return (prefix or "") .. link .. (extras or "")
end
end


return export
return export

Latest revision as of 16:04, 31 May 2024

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
	local alt = data.alt or data.term
	local anchor = data.anchor
	
	local plaenk_alt = mw.loadData("Module:lnk-pro-morph/data").alt
	
	if data.language then
	
		if data.language.code == "lnk-pro" and plaenk_alt[link] then link = plaenk_alt[link] end
		
		if data.hypo then alt = "&#42;&#42;" .. alt end
		
		if data.language.proto then
			if not data.nostar and not data.hypo then alt = "&#42;" .. alt end -- &#42; is an asterisk but sometimes the asterisk gets mistaken for wiki formatting
			link = "Appendix:" .. data.language.name .. "/" .. data.term
			if anchor then link = link .. "#" .. data.language.name .. anchor end
		else
			local jump = data.language.name
			if anchor then jump = data.language.name .. anchor end
			link = link .. "#" .. string.gsub(jump, " ", "_")
		end
		
	end
	
	local term = mw.ustring.match(mw.ustring.gsub(link, "&nbsp;", " "),"([^%#]+)")
	
	if term == mw.title.getCurrentTitle().text and not data.nobold then
		return "<b>" .. alt .. "</b>"
	elseif mw.ustring.match(term, "^[%?%-–—]+$") or mw.ustring.match(term, ":[%?%-–—]+$") or data.nolink then
		return alt
	else
		return "[[" .. link .. "|" .. alt .. "]]"
	end
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)
	link = require("Module:formatting").wrap_face(link, data.language, face or "nil")
	local extras = export.link_extras(data)
	if extras then
		extras = " (" .. extras .. ")"
	end
	local prefix
	if data.language and data.showlanguage then
		prefix = "[[" .. data.language.link .. "|" .. data.language.name .. "]] "
	end
	return (prefix or "") .. link .. (extras or "")
end

return export