Module:etymology/templates: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
language name should probably not be linked, as that's the current behavior |
added "bor" parameter to T:desc, to show right arrow before language name |
||
Line 303: | Line 303: | ||
["tr"] = {}, |
["tr"] = {}, |
||
["sc"] = {}, |
["sc"] = {}, |
||
["bor"] = { boolean = true }, |
|||
} |
} |
||
Line 326: | Line 327: | ||
local link = require("Module:links").full_link({lang = lang, sc = sc, term = term, alt = alt, id = args["id"], tr = args["tr"], genders = args["g"], gloss = args["gloss"], pos = args["pos"], lit = args["lit"]}, face, allowSelfLink) |
local link = require("Module:links").full_link({lang = lang, sc = sc, term = term, alt = alt, id = args["id"], tr = args["tr"], genders = args["g"], gloss = args["gloss"], pos = args["pos"], lit = args["lit"]}, face, allowSelfLink) |
||
local arrow = "" |
|||
⚫ | |||
if args["bor"] then |
|||
arrow = "→ " |
|||
end |
|||
⚫ | |||
end |
end |
||
Revision as of 21:32, 28 March 2017
- The following documentation is located at Module:etymology/templates/documentation. [edit]
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
This module generates content for several etymology templates. They include:
{{etyl}}
Also, the following specialized borrowing templates (not including {{bor}}
/{{borrowed}}
itself):
{{learned borrowing}}
{{semi-learned borrowing}}
{{orthographic borrowing}}
{{unadapted borrowing}}
{{calque}}
{{partial calque}}
{{semantic loan}}
{{phono-semantic matching}}
{{transliteration}}
Miscellaneous etymology templates that take a single term parameter:
{{abbrev}}
{{back-formation}}
{{clipping}}
{{ellipsis}}
{{initialism}}
{{rebracketing}}
{{reduplication}}
- ...
Miscellaneous etymology templates that take no term parameter:
{{onomatopoeic}}
{{unknown}}
{{uncertain}}
- ...
Some templates that used to be here but have now been moved to submodules:
- Module:etymology/templates/cognate:
{{cognate}}
,{{noncognate}}
- Module:etymology/templates/derived:
{{derived}}
- Module:etymology/templates/inherited:
{{inherited}}
- Module:etymology/templates/borrowed:
{{borrowed}}
- Module:etymology/templates/doublet:
{{doublet}}
- Module:etymology/templates/descendant:
{{descendant}}
,{{descendants tree}}
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 = "en"
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"] = {},
["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"] = {},
["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"] = {},
["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"] = {},
["g"] = {},
["gloss"] = {alias_of = "t"},
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = {},
["tr"] = {},
["sc"] = {},
["nocap"] = {type = "boolean"},
["notext"] = {type = "boolean"},
["sort"] = {},
}
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"] = {},
["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["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 "gloss" or 5]},
parts, args["sort"], args["nocap"], args["notext"])
end
function export.descendant(frame)
local namespace = mw.title.getCurrentTitle().nsText
local params = {
[1] = {required = true},
[2] = {},
[3] = {},
[4] = {alias_of = "gloss"},
["g"] = {list = true},
["gloss"] = {},
["id"] = {},
["lit"] = {},
["pos"] = {},
["t"] = {alias_of = "gloss"},
["tr"] = {},
["sc"] = {},
["bor"] = { boolean = true },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = args[1]
local term = args[2]
local alt = args[3]
local sc = args["sc"]
if namespace == "Template" then
lang = "en"
term = "word"
sc = "Latn"
end
lang = m_languages.getByCode(lang) or langError(lang, 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local languageName = lang:getCanonicalName()
local link = require("Module:links").full_link({lang = lang, sc = sc, term = term, alt = alt, id = args["id"], tr = args["tr"], genders = args["g"], gloss = args["gloss"], pos = args["pos"], lit = args["lit"]}, face, allowSelfLink)
local arrow = ""
if args["bor"] then
arrow = "→ "
end
return arrow .. languageName .. ": " .. link
end
return export