Mòdul:etimologia
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Mòdul de suport per a diverses plantilles d’etimologia, especialment per indicar que prové d’una altra llengua.
A més dels codis de llengua d’ús general en les entrades, accepta codis específics usats només en etimologia. Vegeu Mòdul:etimologia/llengua.
local p = {}
local languages = require("Module:llengua")
local general = require("Module:ca-general")
local function parse_2_lang_args(frame) -- from en:Module:etymology/templates/internal
local args = frame:getParent().args
local lang = languages.getByCode(args[2], true)
local source = languages.getByCode(args[1], true)
source.sc = args.sc or source.sc -- TODO: use term.sc instead of term.lang.sc in create_link/full_link
return args, lang, {
lang = source,
sc = args.sc or source.sc,
term = args[3],
alt = args["alt"] or args[4],
tr = args["tr"] or args["trans"],
gloss = args["t"] or args["trad"],
lit = args["lit"]
}
end
local function format_source(lang, source, display_source, nocap, catname)
local display = ""
if display_source then
if source.type == "grup" then
display = (nocap and "d'un " or "D'un ") .. source.name
else
display = general.addParticle(nocap and "del" or "Del", source.name)
end
end
local categories = ""
if lang then
-- Format categories, but only if there is a current language; {{cog}} currently gets no categories
if source.type == "grup" then
source_prep = "d'un " .. source.name
else
source_prep = general.addParticle("del", source.name)
end
local lang_prep = general.addParticle("al", lang.name)
categories = {catname .. " " .. source_prep .. " " .. lang_prep}
categories = require("Module:utilitats").format_categories(categories, lang, sort_key, nil, force_cat)
end
return "<span class=\"etyl\">" .. display .. categories .. "</span>"
end
local function create_link(terminfo)
local link = ""
if terminfo.term and terminfo.term ~= "-" then
link = require("Module:enllaç").full_link(terminfo, "terme", true)
if (link ~= "") then link = " " .. link end
end
return link
end
-- Templates
function p.derived(frame) -- from en:Module:etymology/templates/derived
local nocap = frame.args.nocap
local args, lang, term = parse_2_lang_args(frame)
local link = create_link(term)
local source = format_source(lang, term.lang, link ~= "", nocap, "Derivats") -- do not display source name if there is no link
return source .. link
end
-- Supports various specialized types of borrowings, according to `frame.args.bortype`:
-- Calcs, Calcs semàntics
function p.specialized_borrowing(frame)
local bortype = frame.args.bortype
local display = frame.args.display
local nocap = frame.args.nocap
local args, lang, term = parse_2_lang_args(frame)
local link = create_link(term)
local source = format_source(lang, term.lang, display, nocap, bortype)
return source .. link
end
return p