This is a private module sandbox of Isomorphyc, for their own experimentation. Items in this module may be added and removed at Isomorphyc's discretion; do not rely on this module's stability.


local m_links = require("Module:User:Isomorphyc/links-draft")

local export = {}

-- Used in [[Template:l]] and [[Template:m]]
function export.l_term_t(frame)
	local face = frame.args["face"]
	local allowSelfLink = frame.args["notself"]; allowSelfLink = not allowSelfLink or allowSelfLink == ""
	
	local params = {
		[1] = {required = true},
		[2] = {},
		[3] = {},
		[4] = {alias_of = "gloss"},
		["g"] = {list = true},
		["gloss"] = {},
		["id"] = {},
		["lit"] = {},
		["pos"] = {},
		["t"] = {alias_of = "gloss"},
		["tr"] = {},
		["pr"] = {},
		["sc"] = {},
	}
	
	-- Compatibility mode for {{term}}.
	-- If given a nonempty value, the function uses lang= to specify the
	-- language, and all the positional parameters shift one number lower.
	local compat = (frame.args["compat"] or "") ~= ""
	
	if compat then
		params["lang"] = {},
		table.remove(params, 1)
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = args[compat and "lang" or 1]
	
	-- Tracking for missing language or und
	if not lang then
		require("Module:debug").track("link/no lang")
	elseif lang == "und" then
		require("Module:debug").track("link/und")
	end
	
	lang = lang or "und"
	local sc = args["sc"]
	
	local term = args[(compat and 1 or 2)]
	local alt = args[(compat and 2 or 3)]
	
	-- Check parameters
	lang = require("Module:User:Isomorphyc/languages-draft").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	if not term and not alt and frame.args["demo"] then
		term = frame.args["demo"]
	end
	
	-- Forward the information to full_link
	return m_links.full_link({lang = lang, sc = sc, term = term, alt = alt, id = args["id"], tr = args["tr"], pr = args["pr"], genders = args["g"], gloss = args["gloss"], pos = args["pos"], lit = args["lit"]}, face, allowSelfLink)
end

function export.ll(frame)
	local args = frame:getParent().args
	local allowSelfLink = args["notself"]; allowSelfLink = not allowSelfLink or allowSelfLink == ""
	
	local lang = args[1]
	lang = require("Module:User:Isomorphyc/languages-draft").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	
	local text = args[2]
	local alt = args[3]
	if text == "" then return alt or "" end
	if alt == "" then alt = nil end
	
	local id = args["id"]; if id == "" then id = nil end
	
	return m_links.language_link(text, alt, lang, id, allowSelfLink)
end

function export.def_t(frame)
	local params = {
		[1] = {required = true, default = ""},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	return m_links.english_links(args[1])
end

return export