Module:etymology: Difference between revisions

No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 5: Line 5:


local function term_error(terminfo)
local function term_error(terminfo)
if terminfo.lang:hasType("family") then
if terminfo.lang then
terminfo.term = "-"
if terminfo.lang:hasType("family") then
terminfo.term = "-"
end
end
end
return terminfo
return terminfo
Line 17: Line 19:
if terminfo.term ~= "-" then
if terminfo.term ~= "-" then
-- mw.log(terminfo.term)
-- mw.log(terminfo.term)
link = require("Module:links").full_link(terminfo, "term_i")
link = require("Module:links").full_link(terminfo, "term")
if (link ~= "") then link = " " .. link end
if (link ~= "") then link = " " .. link end
end
end
Line 37: Line 39:
cat_name = "other languages"
cat_name = "other languages"
elseif source:getCode() == "mul" then
elseif source:getCode() == "mul" then
display = "[[w:Translingualism|translingual]]"
display = raw and "translingual" or "[[w:Translingualism|translingual]]"
cat_name = "Translingual"
cat_name = "Translingual"
elseif source:getCode() == "mul-tax" then
elseif source:getCode() == "mul-tax" then
display = "[[w:taxonomic name|taxonomic name]]"
display = raw and "taxonomic name" or "[[w:Biological nomenclature|taxonomic name]]"
cat_name = "taxonomic names"
cat_name = "taxonomic names"
else
else
Line 46: Line 48:
cat_name = source:getDisplayForm()
cat_name = source:getDisplayForm()
end
end
return display, cat_name
return display, cat_name
end
end




function export.insert_source_cat_get_display(categories, lang, source, raw, nocat)
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 68: Line 70:
else
else
table.insert(categories, langname .. " terms derived from " .. cat_name)
table.insert(categories, langname .. " terms derived from " .. cat_name)
if data.borrowing_type then
table.insert(categories, langname .. " terms " .. data.borrowing_type .. " from " .. cat_name)
end
end
end
end
end
Line 75: Line 80:




-- FIXME: rename to format_source()
function export.format_source(data)
function export.format_etyl(lang, source, sort_key, categories, nocat)
local lang, sort_key = data.lang, data.sort_key


local display
local display, categories = export.insert_source_cat_get_display(data)
display, categories = export.insert_source_cat_get_display(categories, lang, source, false, nocat)
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 97:


-- Internal implementation of {{cognate|...}} template
-- Internal implementation of {{cognate|...}} template
function export.format_cognate(terminfo, sort_key)
function export.format_cognate(data)
return export.format_derived(nil, terminfo, sort_key, nil, "cognate")
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 source = terminfo.lang
local lang, terminfo, sort_key, nocat, template_name =
return export.format_etyl(lang, source, sort_key, nil, nocat) .. export.process_and_create_link(terminfo, template_name)
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 145: Line 162:


-- 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
Line 157: Line 175:
export.check_ancestor(lang, source)
export.check_ancestor(lang, source)


return export.format_etyl(lang, source, sort_key, categories, nocat) .. link
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 166: Line 191:
if not (lang:getCode() == source:getCode() or lang:getFullCode() == source:getCode()) then
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 format_etyl().
-- [[:Category:English terms borrowed from English]]; the former is inserted automatically by format_source().
category = " terms borrowed from " .. source:getDisplayForm()
-- The second parameter here doesn't matter as it only affects `display`, which we don't use.
local display, cat_name = export.get_display_and_cat_name(source, "raw")
category = " terms borrowed from " .. cat_name
end
end
if category then
if category then
Line 176: Line 203:


-- 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 212:
end
end


return export.format_etyl(lang, source, sort_key, categories, nocat) ..
return export.format_source {
export.process_and_create_link(terminfo, "borrowed")
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