Module:etymology: Difference between revisions

1,414 bytes removed ,  17 January 2022
no edit summary
No edit summary
No edit summary
Line 33: Line 33:
if terminfo.term ~= "-" then
if terminfo.term ~= "-" then
-- mw.log(terminfo.term)
link = " " .. require("Module:links").full_link(terminfo, "term_i", true)
link = " " .. require("Module:links").full_link(terminfo, "term", true)
end
end
Line 65: Line 64:
else
else
info.display = source:makeWikipediaLink()
info.display = source:makeWikipediaLink()
info.cat_name = source:getDisplayForm()
if source:getType() == "family" then
info.cat_name = source:getCategoryName()
else
info.cat_name = source:getCanonicalName()
end
end
end
Line 107: Line 111:
end
end


-- Return true if `lang` has `otherlang` (which may be an etymology-only language) as an ancestor. This includes
-- cases such as Italian -> Old Italian, which is an etymology-only language whose "parent" is Italian but which is
-- marked as "ancestral to parent". `non_etym_otherlang` is the non-etymology-language equivalent of `otherlang`.
-- If `otherlang` is not an etymology-only language, the two will be the same.
local function hasAncestor(lang, otherlang, non_etym_otherlang)
-- First check if `lang` has (the non-etymology-language parent of) `otherlang` as its ancestor. If `lang` is e.g.
-- Italian and `otherlang` is Latin, this will be caught here. If `lang` is Italian and `otherlang` is Vulgar Latin
-- (an etymology-only language whose parent is Latin), this will also be caught here, as we use the
-- non-etymology-language parent, in this case Latin, when checking the ancestor hierarchy.
if lang:hasAncestor(non_etym_otherlang) then
return true
end
-- Second check for the Italian -> Old Italian case. This happens when (a) `otherlang` is etymology-only,
-- (b) `otherlang` is marked as "ancestral to parent", (c) `otherlang`'s parent is the same as `lang`. This is not
-- caught above because Italian is not ancestral to Italian.
if otherlang:getType() == "etymology language" and otherlang:isAncestralToParent() then
local otherlang_parent = export.getNonEtymological(otherlang)
if otherlang_parent and otherlang_parent:getCode() == lang:getCode() then
return true
end
end
return false
end


-- Internal implementation of {{inherited|...}} template
-- Internal implementation of {{inherited|...}} template
Line 136: Line 117:


terminfo = termError(terminfo)
terminfo = termError(terminfo)
 
local orig_terminfo_lang = terminfo.lang
 
terminfo.lang = export.getNonEtymological(terminfo.lang)
terminfo.lang = export.getNonEtymological(terminfo.lang)


if not hasAncestor(lang, orig_terminfo_lang, terminfo.lang) and mw.title.getCurrentTitle().nsText ~= "Template" then
if not lang:hasAncestor(terminfo.lang) and mw.title.getCurrentTitle().nsText ~= "Template" then
-- All of the code inside this if-clause is for generating the error message.
local function showLanguage(lang)
local function showLanguage(lang)
local retval = ("%s (%s)"):format(lang:makeCategoryLink(), lang:getCode())
return ("[[:Category:%s|%s]] (%s)")
if lang:getType() == "etymology language" then
:format(lang:getCategoryName(), lang:getCanonicalName(), lang:getCode())
retval = retval .. (" (an etymology-only language whose regular parent is %s)"):format(
showLanguage(export.getNonEtymological(lang)))
end
return retval
end
end
local postscript
local postscript
Line 169: Line 143:
end
end
error(("%s is not set as an ancestor of %s in %s. %s")
error(("%s is not set as an ancestor of %s in %s. %s")
:format(showLanguage(orig_terminfo_lang), showLanguage(lang), moduleLink, postscript))
:format(showLanguage(terminfo.lang), showLanguage(lang), moduleLink, postscript))
end
end
Line 195: Line 169:
if lang:getCode() == source:getCode() then
if lang:getCode() == source:getCode() then
table.insert(categories, lang:getCanonicalName() .. " twice-borrowed terms")
table.insert(categories, lang:getCanonicalName() .. " twice-borrowed terms")
elseif source:getType() == "family" then
table.insert(categories, lang:getCanonicalName() .. " terms borrowed from " .. source:getCategoryName())
else
else
table.insert(categories, lang:getCanonicalName() .. " terms borrowed from " .. source:getDisplayForm())
table.insert(categories, lang:getCanonicalName() .. " terms borrowed from " .. source:getCanonicalName())
end
end


Line 205: Line 181:
text = "[[semi-learned borrowing|" .. (nocap and "s" or "S") .. "emi-learned borrowing]] from "
text = "[[semi-learned borrowing|" .. (nocap and "s" or "S") .. "emi-learned borrowing]] from "
elseif borrowing_type == "orthographic" then
elseif borrowing_type == "orthographic" then
text = "[[Appendix:Glossary#orthographic borrowing|" .. (nocap and "o" or "O") .. "rthographic borrowing]] from "
text = "[[orthographic|" .. (nocap and "o" or "O") .. "rthographic]] [[Appendix:Glossary#borrowing|borrowing]] from "
elseif borrowing_type == "unadapted" then
elseif borrowing_type == "unadapted" then
text = "[[Appendix:Glossary#unadapted borrowing|" .. (nocap and "u" or "U") .. "nadapted borrowing]] from "
text = "[[Appendix:Glossary#unadapted borrowing|" .. (nocap and "u" or "U") .. "nadapted borrowing]] from "
Line 216: Line 192:
-- For non-plain borrowings, insert extra category, unless lang and source
-- For non-plain borrowings, insert extra category, unless lang and source
-- are the same (a twice-borrowed term).
-- are the same (a twice-borrowed term).
table.insert(categories, lang:getCanonicalName() .. " " .. borrowing_type .. " borrowings from " ..
local source_name = source:getType() == "family" and source:getCategoryName() or source:getCanonicalName()
source:getDisplayForm())
table.insert(categories, lang:getCanonicalName() .. " " .. borrowing_type .. " borrowings from " .. source_name)
end
end
Line 237: Line 213:
local categories = {}
local categories = {}


category = category:gsub("SOURCE", source:getDisplayForm())
if source:getType() == "family" then
category = category:gsub("SOURCE", source:getCategoryName())
else
category = category:gsub("SOURCE", source:getCanonicalName())
end
table.insert(categories, lang:getCanonicalName() .. " " .. category)
table.insert(categories, lang:getCanonicalName() .. " " .. category)
local link = createLink(terminfo, template_name)
local link = createLink(terminfo, template_name)
result = result .. export.format_etyl(lang, source, sort_key, categories, nocat) .. link
result = result .. " " ..  export.format_etyl(lang, source, sort_key, categories, nocat) .. link
return result
return result
Line 274: Line 254:
-- Internal implementation of {{semantic loan|...}} template
-- Internal implementation of {{semantic loan|...}} template
function export.semantic_loan(lang, terminfo, sort_key, nocap, notext, nocat)
function export.semantic_loan(lang, terminfo, sort_key, nocap, notext, nocat)
local pre_text = ""
local pre_text = ""
Line 286: Line 265:
-- Internal implementation of {{phono-semantic matching|...}} template
-- Internal implementation of {{phono-semantic matching|...}} template
function export.phono_semantic_matching(lang, terminfo, sort_key, nocap, notext, nocat)
function export.phono_semantic_matching(lang, terminfo, sort_key, nocap, notext, nocat)
 
local pre_text = ""
local pre_text = ""