Մոդուլ:etymology
Արտաքին տեսք
Documentation for this module may be created at Մոդուլ:etymology/doc
local export = {}
function export.format_etyl(lang, source, sort_key)
local info
if source:getCode() == "und" then
info = {
display = "undetermined",
cat_name = "other languages"}
elseif source:getType() == "etymology language" then
info = {
display = "[[w:" .. source:getWikipediaArticle() .. "|" .. source:getCanonicalName() .. "]]",
cat_name = source:getCanonicalName()}
elseif source:getType() == "family" then
info = {
display = "[[w:" .. source:getCategoryName() .. "|" .. source:getCanonicalName() .. "]]",
cat_name = source:getCategoryName()}
else
info = {
display = "[[w:" .. source:getWikipediaArticle() .. "|" .. source:getCanonicalName() .. "]]",
cat_name = source:getCanonicalName()}
end
-- Add the categories, but only if there is a current language
local categories = ""
if lang then
local m_utilities = require("Module:utilities")
categories = {}
if lang:getCode() == source:getCode() then
categories = m_utilities.format_categories({lang:getCanonicalName() .. " twice-borrowed terms"}, lang, sort_key)
else
categories = m_utilities.format_categories({lang:getCanonicalName() .. " terms derived from " .. info.cat_name}, lang, sort_key)
end
end
return "<span class=\"etyl\">" .. info.display .. categories .. "</span>"
end
-- Internal implementation of {{derived|...}} and {{der|...}} templates
function export.format_derived(lang, sc, source, term, alt, id, annotations, sort_key)
local linktarget = source
if source:getType() == "etymology language" then
linktarget = require("Module:languages").getByCode(source:getParentCode())
end
local link = ""
if term or alt or id or annotations.tr or annotations.gloss or annotations.pos or annotations.lit then
link = " " .. require("Module:links").full_link(term, alt, linktarget, sc, "term", id, annotations, true)
end
return export.format_etyl(lang, source, sort_key) .. link
end
-- Internal implementation of {{cognate|...}} and {{cog|...}} templates
function export.format_cognate(sc, source, term, alt, id, annotations, sort_key)
return export.format_derived(nil, sc, source, term, alt, id, annotations, sort_key)
end
-- Internal implementation of {{inherited|...}} and {{inh|...}} templates
function export.format_inherited(lang, sc, source, term, alt, id, annotations, sort_key)
local linktarget = source
if source:getType() == "etymology language" then
linktarget = require("Module:languages").getByCode(source:getParentCode())
end
if not lang:hasAncestor(linktarget) and mw.title.getCurrentTitle().nsText ~= "Template" then
error(source:getCanonicalName() .. " is not an ancestor of " .. lang:getCanonicalName() .. ".")
end
local link = ""
if term or alt or id or annotations.tr or annotations.gloss or annotations.pos or annotations.lit then
link = " " .. require("Module:links").full_link(term, alt, linktarget, sc, "term", id, annotations, true)
end
local categories = require("Module:utilities").format_categories({lang:getCanonicalName() .. " terms inherited from " .. source:getCanonicalName()}, lang, sort_key)
return export.format_etyl(nil, source, sort_key) .. link .. categories
end
-- Internal implementation of {{borrowed|...}} and {{bor|...}} templates
function export.format_borrowed(lang, sc, source, term, alt, id, annotations, sort_key, nocap, notext, learned)
if nocap then
require("Module:debug").track("bor/nocap")
end
local linktarget = source
if source:getType() == "etymology language" then
linktarget = require("Module:languages").getByCode(source:getParentCode())
end
local text = ""
local categories = {}
if lang:getCode() == source:getCode() then
table.insert(categories, lang:getCanonicalName() .. " twice-borrowed terms")
elseif source:getType() == "family" then
table.insert(categories, lang:getCanonicalName() .. " terms borrowed from " .. source:getCategoryName())
else
table.insert(categories, lang:getCanonicalName() .. " terms borrowed from " .. source:getCanonicalName())
end
if learned then
text = "[[learned borrowing|" .. (nocap and "l" or "L") .. "earned borrowing]] from "
table.insert(categories, lang:getCanonicalName() .. " learnedly borrowed terms")
else
text = "[[Appendix:Glossary#loanword|" .. (nocap and "b" or "B") .. "orrowing]] from "
end
local link = ""
if term or alt or id or annotations.tr or annotations.gloss or annotations.pos or annotations.lit then
link = " " .. require("Module:links").full_link(term, alt, linktarget, sc, "term", id, annotations, true)
end
local categories = require("Module:utilities").format_categories(categories, lang, sort_key)
return (notext and "" or text) .. export.format_etyl(nil, source, sort_key) .. link .. categories
end
-- Internal implementation of {{calque|...}} template
function export.calque(lang, source, parts, sort_key, nocap, nocat, notext)
local result = ""
if parts and #parts ~= 0 then
result = result .. require("Module:compound").show_compound(lang, nil, parts, nil, nil, nocat)
result = result .. ", [[Appendix:Glossary#calque|calque]] of"
result = result .. "[[Category:calque with terms]] "
elseif not notext then
result = result .. "[[Appendix:Glossary#calque|" .. (nocap and "c" or "C") .. "alque]] of "
end
result = result .. export.format_etyl(lang, source.lang, sort_key)
if source.lang:getType() == "etymology language" then
source.lang = require("Module:languages").getByCode(source.lang:getParentCode())
end
result = result .. " " .. require("Module:links").full_link(source.term, nil, source.lang, nil, "term", nil, {tr = source.tr, gloss = source.gloss}, nil, nil)
return result
end
return export