Module:User:Benwing2/etymology/specialized

local export = {}

-- This function handles all the messiness of different types of specialized borrowings. It should insert any -- borrowing-type-specific categories into `categories` unless `nocat` is given, and return the text to display -- before the source + term (or "" for no text). function export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat) local function non_glossary_link(entry, text) text = text or entry -- FIXME: Uses of this should have glossary entries created and refer to the glossary. if not nocap then text = mw.getContentLanguage:ucfirst(text) end return "" .. text .. "" end

local function glossary_link(entry, text) text = text or entry return non_glossary_link("Appendix:Glossary#" .. entry, text) end

local function inscat(cat) table.insert(categories, lang:getCanonicalName .. " " .. cat) end

local text, category if bortype == "calque" then text = glossary_link("calque") .. " of " category = "terms calqued from " elseif bortype == "partial-calque" then text = glossary_link("partial calque") .. " of " category = "terms partially calqued from " elseif bortype == "semantic-loan" then text = glossary_link("semantic loan") .. " from " category = "semantic loans from " elseif bortype == "transliteration" then -- FIXME, create entry in Appendix:Glossary text = non_glossary_link("transliteration") .. " of " category = "transliterations of SOURCE terms" -- It seems the intent of the former code was to insert two categories, but it never worked. -- if not nocat then --	inscat(" terms borrowed from " .. source:getDisplayForm) -- end elseif bortype == "phono-semantic-matching" then -- FIXME, create entry in Appendix:Glossary text = non_glossary_link("w:Phono-semantic matching", "phono-semantic matching") .. " of " category = "phono-semantic matchings from " else local lang_is_source = lang:getCode == source:getCode if not nocat then if lang_is_source then inscat(" twice-borrowed terms") else inscat(" terms borrowed from " .. source:getDisplayForm) category = bortype .. " borrowings from " end end if bortype == "learned" then -- FIXME, create entry in Appendix:Glossary text = non_glossary_link("learned borrowing") .. " from " elseif bortype == "semi-learned" then -- FIXME, create entry in Appendix:Glossary text = non_glossary_link("semi-learned borrowing") .. " from " elseif bortype == "orthographic" then text = glossary_link("orthographic borrowing") .. " from " elseif bortype == "unadapted" then text = glossary_link("unadapted borrowing") .. " from " else error("Internal error: Unrecognized bortype: " .. bortype) end end

if category and not nocat then local sourcedisp = source:getDisplayForm if category:find("SOURCE") then category = category:gsub("SOURCE", sourcedisp) else category = category .. sourcedisp end inscat(category) end

return text end

function export.specialized_borrowing(bortype, lang, terminfo, sort_key, nocap, notext, nocat) local m_etymology = require("Module:User:Benwing2/etymology") local categories = {} local source = terminfo.lang local text = export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat) text = notext and "" or text return text .. m_etymology.format_etyl(lang, source, sort_key, categories, nocat) .. m_etymology.process_and_create_link(terminfo, template_name) end

function export.specialized_multi_borrowing(bortype, lang, sources, terminfo, sort_key, nocap, notext, nocat) local categories = {} local text

for _, source in ipairs(sources) do		text = export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat) end text = notext and "" or text return text .. require("Module:User:Benwing2/etymology/multi").format_sources(lang, sources, terminfo, sort_key, categories, nocat) .. require("Module:User:Benwing2/etymology").process_and_create_link(terminfo, template_name) end

return export