Module:etymology: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 33: Line 33:
if terminfo.term ~= "-" then
if terminfo.term ~= "-" then
link = " " .. require("Module:links").full_link(terminfo, "term_i", true)
-- mw.log(terminfo.term)
link = " " .. require("Module:links").full_link(terminfo, "term", true)
end
end
Line 64: Line 65:
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 111: Line 107:
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 117: Line 136:


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 lang:hasAncestor(terminfo.lang) and mw.title.getCurrentTitle().nsText ~= "Template" then
if not hasAncestor(lang, orig_terminfo_lang, 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)
return ("[[:Category:%s|%s]] (%s)")
local retval = ("%s (%s)"):format(lang:makeCategoryLink(), lang:getCode())
:format(lang:getCategoryName(), lang:getCanonicalName(), lang:getCode())
if lang:getType() == "etymology language" then
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 143: Line 169:
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(terminfo.lang), showLanguage(lang), moduleLink, postscript))
:format(showLanguage(orig_terminfo_lang), showLanguage(lang), moduleLink, postscript))
end
end
Line 169: Line 195:
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:getCanonicalName())
table.insert(categories, lang:getCanonicalName() .. " terms borrowed from " .. source:getDisplayForm())
end
end


Line 181: Line 205:
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 = "[[orthographic|" .. (nocap and "o" or "O") .. "rthographic]] [[Appendix:Glossary#borrowing|borrowing]] from "
text = "[[Appendix:Glossary#orthographic borrowing|" .. (nocap and "o" or "O") .. "rthographic 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 192: Line 216:
-- 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).
local source_name = source:getType() == "family" and source:getCategoryName() or source:getCanonicalName()
table.insert(categories, lang:getCanonicalName() .. " " .. borrowing_type .. " borrowings from " ..
table.insert(categories, lang:getCanonicalName() .. " " .. borrowing_type .. " borrowings from " .. source_name)
source:getDisplayForm())
end
end
Line 213: Line 237:
local categories = {}
local categories = {}


if source:getType() == "family" then
category = category:gsub("SOURCE", source:getDisplayForm())
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 254: Line 274:
-- 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 265: Line 286:
-- 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 = ""