Module:etymology/specialized
Jump to navigation
Jump to search
- The following documentation is located at Module:etymology/specialized/documentation. [edit]
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
This module generates content for all specialized borrowing templates, i.e. not including {{borrowed}}
but including the following:
{{learned borrowing}}
{{semi-learned borrowing}}
{{orthographic borrowing}}
{{unadapted borrowing}}
{{calque}}
{{partial calque}}
{{semantic loan}}
{{phono-semantic matching}}
{{transliteration}}
The code for these templates is placed in its own module to save memory in the common case where {{borrowed}}
is used.
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, senseid)
local function non_glossary_link(entry, text)
text = text or entry
if not nocap and not senseid then
text = mw.getContentLanguage():ucfirst(text)
end
if senseid then
senseids = mw.text.split(senseid, '!!')
output = {}
for i, id in ipairs(senseids) do
if i == 1 and not nocap then
uc = '|uc=1'
else
uc = ''
end
table.insert(output, mw.getCurrentFrame():preprocess('{{senseno|' .. lang:getCode() .. '|' .. id .. uc .. '}}'))
end
if senseid:find('!!') then
copula = ' are '
article = ''
plural = 's'
else
copula = ' is '
article = ' a '
plural = ''
end
return mw.text.listToText(output) .. copula .. article .. '[[' .. entry .. '|' .. text .. plural .. ']]'
else
return "[[" .. entry .. "|" .. text .. "]]"
end
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
text = 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
text = glossary_link("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
text = glossary_link("learned borrowing") .. " from "
elseif bortype == "semi-learned" then
text = 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, senseid, template_name)
local m_etymology = require("Module:etymology")
local categories = {}
local source = terminfo.lang
local text = export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat, senseid)
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, sc, sources, terminfo, sort_key, nocap, notext, nocat, conj, senseid, template_name)
local categories = {}
local text
for _, source in ipairs(sources) do
text = export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat, senseid)
end
text = notext and "" or text
return text .. require("Module:etymology/multi").format_sources(lang, sc, sources, terminfo, sort_key, categories, nocat, conj) ..
require("Module:etymology").process_and_create_link(terminfo, template_name)
end
return export