Modul:etymology/templates
Dokumentasjon for modulen kan opprettast på Modul:etymology/templates/dok
local export = {}
local m_languages = require("Module:languages")
function fetch_lang(lang, parameter)
return m_languages.getByCode(lang) or m_languages.err(lang, parameter)
end
function fetch_source(code, disallow_family)
local source =
m_languages.getByCode(code)
or require("Module:etymology languages").getByCode(code)
or not disallow_family and require("Module:families").getByCode(code)
if source then
return source
else
error("The language" .. (not disallow_family and ", family" or "") .. " or etymology language code \"" .. code .. "\" is not valid.")
end
end
function fetch_script(sc)
if sc then
return require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
else
return nil
end
end
function export.etyl(frame)
local params = {
[1] = {required = true, default = "und"},
[2] = {},
["sort"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local source = fetch_source(args[1])
local lang = args[2]
local sort_key = args["sort"]
-- Empty language means English, but "-" means no language. Yes, confusing...
if not lang then
lang = "nn"
elseif lang == "-" then
lang = nil
end
if lang then
lang = fetch_lang(lang, 2)
end
if lang and (lang:getCode() == "la" or lang:getCode() == "nl") then
require("Module:debug").track("etyl/" .. lang:getCode())
require("Module:debug").track("etyl/" .. lang:getCode() .. "/" .. source:getCode())
end
return require("Module:etymology").format_etyl(lang, source, sort_key)
end
function export.cognate(frame)
local params = {
[1] = {required = true, default = "und"},
[2] = {},
[3] = {alias_of = "alt"},
[4] = {alias_of = "t"},
["alt"] = {},
['k'] = {alias_of = 'g'},
["g"] = {},
["gloss"] = { alias_of = "t" },
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = {},
["tr"] = {},
["sc"] = {},
["sort"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local source = fetch_source(args[1])
local sc = fetch_script(args["sc"])
return require("Module:etymology").format_cognate(
{
lang = source,
sc = sc,
term = args[2],
alt = args["alt"],
id = args["id"],
genders = {args["g"]},
tr = args["tr"],
gloss = args["t"],
pos = args["pos"],
lit = args["lit"]
},
args["sort"])
end
function export.noncognate(frame)
return export.cognate(frame)
end
function export.derived(frame)
local params = {
[1] = {required = true, default = "und"},
[2] = {required = true, default = "und"},
[3] = {},
[4] = {alias_of = "alt"},
[5] = {alias_of = "t"},
["alt"] = {},
['k'] = {alias_of = 'g'},
["g"] = {},
["gloss"] = {alias_of = "t"},
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = {},
["tr"] = {},
["sc"] = {},
["sort"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = fetch_lang(args[1], 1)
local source = fetch_source(args[2])
local sc = fetch_script(args["sc"])
return require("Module:etymology").format_derived(
lang,
{
lang = source,
sc = sc,
term = args[3],
alt = args["alt"],
id = args["id"],
genders = { args["g"] },
tr = args["tr"],
gloss = args["t"],
pos = args["pos"],
lit = args["lit"]
},
args["sort"])
end
function export.inherited(frame)
local params = {
[1] = {required = true, default = "und"},
[2] = {required = true, default = "und"},
[3] = {},
[4] = {alias_of = "alt"},
[5] = {alias_of = "t"},
["alt"] = {},
['k'] = {alias_of = 'g'},
["g"] = {},
["gloss"] = {alias_of = "t"},
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = {},
["tr"] = {},
["sc"] = {},
["sort"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = fetch_lang(args[1], 1)
local source = fetch_source(args[2], "no family")
local sc = fetch_script(args["sc"])
return require("Module:etymology").format_inherited(
lang,
{
lang = source,
sc = sc,
term = args[3],
alt = args["alt"],
id = args["id"],
genders = {args["g"]},
tr = args["tr"],
gloss = args["t"],
pos = args["pos"],
lit = args["lit"]
},
args["sort"])
end
function export.borrowed(frame)
local learned = frame.args["learned"]; if not learned or learned == "" then learned = false else learned = true end
local params = {
[1] = {required = true, default = "und"},
[2] = {required = true, default = "und"},
[3] = {},
[4] = {alias_of = "alt"},
[5] = {alias_of = "t"},
["alt"] = {},
['k'] = {alias_of = 'g'},
["g"] = {},
["gloss"] = {alias_of = "t"},
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = {},
["tr"] = {},
["sc"] = {},
["nocap"] = {type = "boolean"},
["notext"] = {type = "boolean"},
["sort"] = {},
["ger"] = {type = "boolean"},
}
local compat = false
if frame:getParent().args["lang"] then
compat = true
end
if compat then
require("Module:debug").track("borrowing/lang")
params["lang"] = table.remove(params, 1)
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = fetch_lang(args[compat and "lang" or 1], compat and "lang" or 1)
local source = fetch_source(args[compat and 1 or 2])
local sc = fetch_script(args["sc"])
return require("Module:etymology").format_borrowed(
lang,
{lang = source, sc = sc, term = args[compat and 2 or 3], alt = args["alt"], id = args["id"], genders = {args["g"]}, tr = args["tr"], gloss = args["t"], pos = args["pos"], lit = args["lit"]},
args["sort"], args["nocap"], args["notext"], learned)
end
function export.calque(frame)
local params = {
[1] = {required = true, default = "und"},
[2] = {required = true, default = "und"},
[3] = {},
[4] = {alias_of = "alt"},
[5] = {alias_of = "t"},
["alt"] = {},
['k'] = {alias_of = 'g'},
["g"] = {},
["gloss"] = {alias_of = "t"},
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = {},
["tr"] = {},
["sort"] = {},
["nocap"] = {type = "boolean"},
["notext"] = {type = "boolean"},
}
local compat_etyl = false
if frame:getParent().args["etyl lang"] then
compat_etyl = true
end
if compat_etyl then
require("Module:debug").track("calque/etyl")
params["etyl lang"] = {required = true, default = "und"}
params["etyl term"] = {}
params["etyl t"] = {}
params["etyl tr"] = {}
params[2] = {list = true, allow_holes = true}
params[3] = nil
params[4] = nil
params[5] = nil
params["alt"] = {list = true, allow_holes = true}
params['k'] = nil
params["g"] = nil
params["gloss"] = {alias_of = "t", list = true, allow_holes = true}
params["id"] = nil
params["lit"] = nil
params["pos"] = {list = true, allow_holes = true}
params["t"] = {list = true, allow_holes = true}
params["tr"] = {list = true, allow_holes = true}
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = fetch_lang(args[1], 1)
local source = fetch_source(args[compat_etyl and "etyl lang" or 2])
local parts = {}
if compat_etyl then
local numParts = math.max(args[2].maxindex, args["alt"].maxindex, args["t"].maxindex, args["tr"].maxindex);
for i = 1, numParts do
table.insert(parts, {
term = args[2][i],
alt = args["alt"][i],
tr = args["tr"][i],
gloss = args["t"][i],
pos = args["pos"][i],
})
end
if numParts > 1 then
require("Module:debug").track("calque/parts")
end
end
return require("Module:etymology").calque(
lang,
{
lang = source,
term = args[compat_etyl and "etyl term" or 3],
alt = not compat_etyl and args[4] or nil,
tr = args[compat_etyl and "etyl tr" or "tr"],
gloss = args[compat_etyl and "etyl t" or "t" or 5]
},
parts,
args["sort"],
args["nocap"],
args["notext"])
end
local function qualifier(content)
if content then
return table.concat{
'<span class="ib-brac qualifier-brac">(</span>',
'<span class="ib-content qualifier-content">',
content,
'</span>',
'<span class="ib-brac qualifier-brac">)</span>'
}
end
end
function export.descendant(frame)
local namespace = mw.title.getCurrentTitle().nsText
local params = {
[1] = { required = true },
[2] = {},
[3] = {},
[4] = { alias_of = "gloss" },
['k'] = {alias_of = 'g'},
["g"] = { },
["gloss"] = {},
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = { alias_of = "gloss" },
["tr"] = {},
["sc"] = {},
["bor"] = { type = "boolean" },
["der"] = { type = "boolean" },
["calq"] = { type = "boolean" },
["calque"] = { alias_of = "calq" },
["alts"] = { type = "boolean" },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = args[1]
local term = args[2]
local alt = args[3]
local tr = args["tr"]
local sc = args["sc"]
if namespace == "Template" then
if not ( sc or lang ) then
sc = "Latn"
end
if not lang then
lang = "en"
end
if not term then
term = "word"
end
end
lang = m_languages.getByCode(lang)
or require("Module:etymology languages").getByCode(lang)
or m_languages.err(lang, 1)
local entryLang = require("Module:etymology").getNonEtymological(lang)
if lang:getCode() ~= entryLang:getCode() then
-- [[Special:WhatLinksHere/Template:tracking/descendant/etymological]]
require("Module:debug").track("descendant/etymological")
require("Module:debug").track("descendant/etymological/" .. lang:getCode())
end
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local languageName = lang:getCanonicalName()
languageName = mw.ustring.gsub(languageName, "^Proto%-", "")
local link = ""
if term ~= "-" then
link = require("Module:links").full_link(
{
lang = entryLang,
sc = sc,
term = term,
alt = alt,
id = args["id"],
tr = tr,
genders = args["g"],
gloss = args["gloss"],
pos = args["pos"],
lit = args["lit"],
},
nil,
true
)
end
local arrow, alts, calque
if args["bor"] or args["calq"] then
arrow = "→ "
elseif args["der"] then
arrow = "⇒ "
else
arrow = ""
end
if args["alts"] then
alts = require("Module:descendants tree").getAlternativeForms(entryLang, term)
else
alts = ""
end
if args["calq"] then
calque = " " .. qualifier("calque")
else
calque = ""
end
return table.concat{arrow, languageName, ": ", link, alts, calque}
end
return export