Module:links: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
Line 1: Line 1:
local export = {}
local export = {}


local function make_list(frame, link_type)
function export.make_link(args)
if link_type ~= "mention" and link_type ~= "list" then
if (not args["link_type"]) or (args["link_type"] ~= "mention" and args["link_type"] ~= "list") then
error("Link type must be specified")
error("Link type must be specified")
end
end
local language_code = frame.args[1]
if not args["code"] then
local word = frame.args[2]
error("Language code must be specified")
local display = frame.args[3] or frame.args["display"] or frame.args["d"]
end
local text = frame.args[4] or frame.args["text"] or frame.args["t"]
local word = args["word"]
local display = args["display"]
local text = frame.args["text"]
local pos = frame.args["pos"]
local pos = frame.args["pos"]
local language = require("Module:languages").get_by_code(language_code)
local language = require("Module:languages").get_by_code(args["code"])
local link = ""
local link = ""
if link_type == "mention" then
if link_type == "mention" then
Line 35: Line 37:
end
end
return link
return link
end
function export.make_list_link(args)
args["link_type"] = "list"
return export.make_link(args)
end
function export.make_mention_link(args)
args["link_type"] = "mention"
return export.make_link(args, "mention")
end
local function make_from_frame(frame, link_type)
local args = (frame:getParent() and frame:getParent().args) or frame.args
return export.make_link{
["code"] = args[1],
["word"] = args[2],
["display"] = args[3] or args["d"] or args["display"],
["text"] = args[4] or args["t"] or args["text"],
["pos"] = args["pos"]
}
end
end


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


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


return export
return export