Modul:etymology/templates/internal

Dokumentasi untuk modul ini dapat dibuat di Modul:etymology/templates/internal/doc

-- For internal use only with [[Modul:etymology/templates]] and its submodules.

local export = {}

function export.fetch_lang(lang, param)
	return require("Modul:languages").getByCode(lang, param)
end


function export.fetch_source(code, param, disallow_family)
	return require("Modul:languages").getByCode(code, param, true, not disallow_family)
end


local function fetch_sources(codes, param, disallow_family)
	local m_languages = require("Modul:languages")
	codes = mw.text.split(codes, "%s*,%s*")
	for i, code in ipairs(codes) do
		codes[i] = m_languages.getByCode(code, param, true, not disallow_family)
	end
	return codes
end


function export.fetch_source_or_sources(source, param, disallow_family)
	local sources
	if source:find(",") then
		sources = fetch_sources(source, param, no_family)
		source = sources[#sources]
	else
		source = export.fetch_source(source, param, no_family)
	end
	return source, sources
end


function export.fetch_script(sc, param)
	return require("Modul:scripts").getByCode(sc, param)
end


function export.parse_2_lang_args(frame, has_text, no_family)
	local params = {
		[1] = {required = true, default = "und"},
		[2] = {required = true, default = "und"},
		[3] = {},
		[4] = {alias_of = "alt"},
		[5] = {alias_of = "t"},
		
		["alt"] = {},
		["cat"] = {},
		["g"] = {list = true},
		["gloss"] = {alias_of = "t"},
		["id"] = {},
		["lit"] = {},
		["pos"] = {},
		["t"] = {},
		["tr"] = {},
		["ts"] = {},
		["sc"] = {},

		["nocat"] = {type = "boolean"},
		["sort"] = {},
		["conj"] = {},
	}

	if has_text then
		params["notext"] = {type = "boolean"}
		params["nocap"] = {type = "boolean"}
	end

	local args = require("Modul:parameters").process(frame:getParent().args, params)
	
	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")

	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

return export