45,647
edits
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
local function term_error(terminfo) | local function term_error(terminfo) | ||
if terminfo.lang:hasType("family") then | |||
terminfo.term = "-" | terminfo.term = "-" | ||
end | end | ||
return terminfo | return terminfo | ||
end | end | ||
Line 17: | Line 17: | ||
if terminfo.term ~= "-" then | if terminfo.term ~= "-" then | ||
-- mw.log(terminfo.term) | -- mw.log(terminfo.term) | ||
link = require("Module:links").full_link(terminfo, " | link = require("Module:links").full_link(terminfo, "term") | ||
if (link ~= "") then link = " " .. link end | if (link ~= "") then link = " " .. link end | ||
end | end | ||
Line 51: | Line 51: | ||
function export.insert_source_cat_get_display(categories, lang, source, | function export.insert_source_cat_get_display(data) | ||
local display, cat_name = export.get_display_and_cat_name(source, raw) | local categories, lang, source = data.categories, data.lang, data.source | ||
local display, cat_name = export.get_display_and_cat_name(source, data.raw) | |||
if lang and not nocat then | if lang and not data.nocat then | ||
-- Add the category, but only if there is a current language | -- Add the category, but only if there is a current language | ||
if not categories then | if not categories then | ||
Line 60: | Line 61: | ||
end | end | ||
local langname = lang: | local langname = lang:getFullName() | ||
-- If `lang` is an etym-only language, we need to check both it and its parent full language against `source`. | -- If `lang` is an etym-only language, we need to check both it and its parent full language against `source`. | ||
-- Otherwise if e.g. `lang` is Medieval Latin and `source` is Latin, we'll end up wrongly constructing a | -- Otherwise if e.g. `lang` is Medieval Latin and `source` is Latin, we'll end up wrongly constructing a | ||
-- category 'Latin terms derived from Latin'. | -- category 'Latin terms derived from Latin'. | ||
if lang:getCode() == source:getCode() or lang: | if lang:getCode() == source:getCode() or lang:getFullCode() == source:getCode() then | ||
table.insert(categories, langname .. " terms borrowed back into " .. langname) | table.insert(categories, langname .. " terms borrowed back into " .. langname) | ||
else | else | ||
table.insert(categories, langname .. " terms derived from " .. cat_name) | table.insert(categories, langname .. " " .. (data.borrowing_type or "terms derived") .. " from " .. | ||
cat_name) | |||
end | end | ||
end | end | ||
Line 75: | Line 77: | ||
function export.format_source(data) | |||
local lang, sort_key = data.lang, data.sort_key | |||
local | local display, categories = export.insert_source_cat_get_display(data) | ||
if lang and not data.nocat then | |||
if lang and not nocat then | |||
-- Format categories, but only if there is a current language; {{cog}} currently gets no categories | -- Format categories, but only if there is a current language; {{cog}} currently gets no categories | ||
categories = require("Module:utilities").format_categories(categories, lang, sort_key, nil, force_cat) | categories = require("Module:utilities").format_categories(categories, lang, sort_key, nil, | ||
data.force_cat or force_cat) | |||
else | else | ||
categories = "" | categories = "" | ||
Line 92: | Line 94: | ||
-- Internal implementation of {{cognate|...}} template | -- Internal implementation of {{cognate|...}} template | ||
function export.format_cognate( | function export.format_cognate(data) | ||
return export.format_derived | return export.format_derived { | ||
terminfo = data.terminfo, | |||
sort_key = data.sort_key, | |||
template_name = "cognate", | |||
} | |||
end | end | ||
-- Internal implementation of {{derived|...}} template | -- Internal implementation of {{derived|...}} template | ||
function export.format_derived(lang, terminfo, sort_key, nocat, template_name | function export.format_derived(data) | ||
local lang, terminfo, sort_key, nocat, template_name = | |||
return export. | data.lang, data.terminfo, data.sort_key, data.nocat, data.template_name | ||
return export.format_source { | |||
lang = lang, | |||
source = terminfo.lang, | |||
sort_key = sort_key, | |||
nocat = nocat, | |||
borrowing_type = data.borrowing_type, | |||
force_cat = data.force_cat, | |||
} .. export.process_and_create_link(terminfo, template_name) | |||
end | end | ||
Line 124: | Line 138: | ||
local etymModuleLink = lang:hasType("etymology-only") and "[[Module:etymology languages/data]] or " or "" | local etymModuleLink = lang:hasType("etymology-only") and "[[Module:etymology languages/data]] or " or "" | ||
local moduleLink = "[[Module:" | local moduleLink = "[[Module:" | ||
.. require("Module:languages").getDataModuleName(lang: | .. require("Module:languages").getDataModuleName(lang:getFullCode()) | ||
.. "]]" | .. "]]" | ||
if not ancestors[1] then | if not ancestors[1] then | ||
Line 145: | Line 159: | ||
-- Internal implementation of {{inherited|...}} template | -- Internal implementation of {{inherited|...}} template | ||
function export.format_inherited(lang, terminfo, sort_key, nocat | function export.format_inherited(data) | ||
local lang, terminfo, sort_key, nocat = data.lang, data.terminfo, data.sort_key, data.nocat | |||
local source = terminfo.lang | local source = terminfo.lang | ||
local categories = {} | local categories = {} | ||
if not nocat then | if not nocat then | ||
table.insert(categories, lang: | table.insert(categories, lang:getFullName() .. " terms inherited from " .. source:getCanonicalName()) | ||
end | end | ||
Line 157: | Line 172: | ||
export.check_ancestor(lang, source) | export.check_ancestor(lang, source) | ||
return export. | return export.format_source { | ||
lang = lang, | |||
source = source, | |||
sort_key = sort_key, | |||
categories = categories, | |||
nocat = nocat, | |||
force_cat = data.force_cat, | |||
} .. link | |||
end | end | ||
Line 164: | Line 186: | ||
local category | local category | ||
-- Do the same check as in insert_source_cat_get_display() (inverted). | -- Do the same check as in insert_source_cat_get_display() (inverted). | ||
if not (lang:getCode() == source:getCode() or lang: | if not (lang:getCode() == source:getCode() or lang:getFullCode() == source:getCode()) then | ||
-- If both are the same, we want e.g. [[:Category:English terms borrowed back into English]] not | -- If both are the same, we want e.g. [[:Category:English terms borrowed back into English]] not | ||
-- [[:Category:English terms borrowed from English]]; the former is inserted automatically by | -- [[:Category:English terms borrowed from English]]; the former is inserted automatically by format_source(). | ||
category = " terms borrowed from " .. source:getDisplayForm() | category = " terms borrowed from " .. source:getDisplayForm() | ||
end | end | ||
if category then | if category then | ||
table.insert(categories, lang: | table.insert(categories, lang:getFullName() .. category) | ||
end | end | ||
end | end | ||
Line 176: | Line 198: | ||
-- Internal implementation of {{borrowed|...}} template. | -- Internal implementation of {{borrowed|...}} template. | ||
function export.format_borrowed(lang, terminfo, sort_key, nocat | function export.format_borrowed(data) | ||
local lang, terminfo, sort_key, nocat = data.lang, data.terminfo, data.sort_key, data.nocat | |||
local source = terminfo.lang | local source = terminfo.lang | ||
Line 184: | Line 207: | ||
end | end | ||
return export. | return export.format_source { | ||
lang = lang, | |||
source = source, | |||
sort_key = sort_key, | |||
categories = categories, | |||
nocat = nocat, | |||
force_cat = data.force_cat, | |||
} .. export.process_and_create_link(terminfo, "borrowed") | |||
end | end | ||
return export | return export |