Module:etymology/templates/internal: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- For internal use only with [[Module:etymology/templates]] and its submodules.
-- For internal use only with [[Module:etymology/templates]] and its submodules.
local process_params = require("Module:parameters").process


local export = {}
local export = {}


function export.fetch_lang(lang, param)
do
return require("Module:languages").getByCode(lang, param)
local function get_params(frame, has_text, no_family)
end
local alias_of_t = {alias_of = "t"}
 
local boolean = {type = "boolean"}
 
local plain = {}
function export.fetch_source(code, param, disallow_family)
local params = {
return require("Module:languages").getByCode(code, param, true, not disallow_family)
[1] = {
end
required = true,
 
type = "language",
 
default = "und"
local function fetch_sources(codes, param, disallow_family)
},
local m_languages = require("Module:languages")
[2] = {
codes = mw.text.split(codes, "%s*,%s*")
required = true,
for i, code in ipairs(codes) do
sublist = true,
codes[i] = m_languages.getByCode(code, param, true, not disallow_family)
type = "language",
family = not no_family,
default = "und"
},
[3] = plain,
[4] = {alias_of = "alt"},
[5] = alias_of_t,
["alt"] = plain,
["cat"] = plain,
["g"] = {list = true},
["gloss"] = alias_of_t,
["id"] = plain,
["lit"] = plain,
["pos"] = plain,
["t"] = plain,
["tr"] = plain,
["ts"] = plain,
["sc"] = {type = "script"},
["senseid"] = plain,
["nocat"] = boolean,
["sort"] = plain,
["conj"] = plain,
}
if has_text then
params["notext"] = boolean
params["nocap"] = boolean
end
return process_params(frame:getParent().args, params)
end
end
return codes
end
function export.parse_2_lang_args(frame, has_text, no_family)
 
local args = get_params(frame, has_text, no_family)
 
local sources = args[2]
function export.fetch_source_or_sources(source, param, disallow_family)
return args, args[1], {
local sources
lang = sources[#sources],
if source:find(",") then
sc = args["sc"],
sources = fetch_sources(source, param, no_family)
term = args[3],
source = sources[#sources]
alt = args["alt"],
else
id = args["id"],
source = export.fetch_source(source, param, no_family)
genders = args["g"],
end
tr = args["tr"],
return source, sources
ts = args["ts"],
end
gloss = args["t"],
 
pos = args["pos"],
 
lit = args["lit"]
function export.fetch_script(sc, param)
}, #sources > 1 and sources or nil
return require("Module:scripts").getByCode(sc, param)
end
 
 
function export.parse_2_lang_args(frame, has_text, no_family)
local params = {
[1] = true,
[2] = true,
[3] = false,
["alt"] = {aliases = {4}},
["cat"] = false,
["id"] = false,
["lit"] = false,
["pos"] = false,
["t"] = {aliases = {5, "gloss"}},
["tr"] = false,
["ts"] = false,
["sc"] = false,
["senseid"] = false,
 
["nocat"] = false,
["sort"] = false,
["conj"] = false,
}
 
if has_text then
params["notext"] = false
params["nocap"] = false
end
end
local args = require("Module:parameters/lite").process(frame:getParent().args, params)
local yesno = require("Module:yesno")
args["g"] = require("Module:parameters/lite/list")(frame:getParent().args, "g")
args["nocat"] = yesno(args["nocat"])
if has_text then
args["notext"] = yesno(args["notext"])
args["nocap"] = yesno(args["nocap"])
end
local lang = export.fetch_lang(args[1], 1)
local source, sources = export.fetch_source_or_sources(args[2], 2, no_family)
local sc = export.fetch_script(args["sc"], "sc") or require("Module:scripts").getByCode(args[2])
return args, lang, {
lang = source,
sc = sc,
term = args[3],
alt = args["alt"],
id = args["id"],
genders = args["g"],
tr = args["tr"],
ts = args["ts"],
gloss = args["t"],
pos = args["pos"],
lit = args["lit"]
}, sources
end
end


return export
return export

Latest revision as of 10:30, 7 August 2024

Documentation for this module may be created at Module:etymology/templates/internal/doc

-- For internal use only with [[Module:etymology/templates]] and its submodules.
local process_params = require("Module:parameters").process

local export = {}

do
	local function get_params(frame, has_text, no_family)
		local alias_of_t = {alias_of = "t"}
		local boolean = {type = "boolean"}
		local plain = {}
		local params = {
			[1] = {
				required = true,
				type = "language",
				default = "und"
			},
			[2] = {
				required = true,
				sublist = true,
				type = "language",
				family = not no_family,
				default = "und"
			},
			[3] = plain,
			[4] = {alias_of = "alt"},
			[5] = alias_of_t,
			
			["alt"] = plain,
			["cat"] = plain,
			["g"] = {list = true},
			["gloss"] = alias_of_t,
			["id"] = plain,
			["lit"] = plain,
			["pos"] = plain,
			["t"] = plain,
			["tr"] = plain,
			["ts"] = plain,
			["sc"] = {type = "script"},
			["senseid"] = plain,
	
			["nocat"] = boolean,
			["sort"] = plain,
			["conj"] = plain,
		}
		if has_text then
			params["notext"] = boolean
			params["nocap"] = boolean
		end
		return process_params(frame:getParent().args, params)
	end
	
	function export.parse_2_lang_args(frame, has_text, no_family)
		local args = get_params(frame, has_text, no_family)
		local sources = args[2]
		return args, args[1], {
			lang = sources[#sources],
			sc = args["sc"],
			term = args[3],
			alt = args["alt"],
			id = args["id"],
			genders = args["g"],
			tr = args["tr"],
			ts = args["ts"],
			gloss = args["t"],
			pos = args["pos"],
			lit = args["lit"]
		}, #sources > 1 and sources or nil
	end
end

return export