Modul:etymology
Roman
Dokumentasi untuk modul ini dapat dibuat di Modul:etymology/doc
local p = {}
local linksModule = require('Modul:links')
local langModule = require('Modul:lang')
local U = require('Modul:utilities')
-- Etymology type labels
p.etymtypes = {
borrowed = "Pinjeman",
derived = "Turunan",
inherited = "Terusan",
["pseudo-loan"] = "Pinjeman bodong",
compound = "Ambrekan",
blend = "Takopan",
reduplication = "Ulangan"
}
-- Multi-entry etymtypes
local multiEntryTypes = {
compound = true,
blend = true,
reduplication = true
}
-- Generate link to Wikikamus explanation page
local function makeEtymLink(etymtype, nocap_flag)
if not etymtype or etymtype == "" then return "" end
local anchor = string.lower(etymtype)
local display = (nocap_flag == "1") and string.lower(etymtype) or etymtype
return string.format("[[Wikikamus:Daptar setilah#%s|%s]]", anchor, display)
end
-- Main render
function p.render(frame)
local args = frame.args
local lang1 = langModule.getLangCode({args={args[1] or ""}})
local lang2 = args[2] or ""
local etymkey = args.type or ""
local etymtype = p.etymtypes[etymkey] or ""
local nocap_flag = args.nocap or ""
local notext = args.notext or ""
-- Collect entries (multiple supported)
local entries = {}
local i = 1
while args[i+2] do
local entry = args[i+2]
if entry and entry ~= "" then
table.insert(entries, entry)
end
i = i + 1
end
if #entries == 0 and (args[3] or "") ~= "" then
table.insert(entries, args[3])
end
local entryLinks = {}
for idx, rawEntry in ipairs(entries) do
local entryArgs = {
[1] = (multiEntryTypes[etymkey]) and lang1 or lang2,
[2] = rawEntry,
noitalic = args.noitalic or "",
q = args["q"..idx] or (idx == 1 and args.q) or "",
idx = idx,
-- forward extra params
tr = args["tr"..idx] or args.tr or "",
t = args["t"..idx] or args.t or "",
lit = args["lit"..idx] or args.lit or "",
id = args["id"..idx] or args.id or "",
class = args["class"..idx] or args.class or "",
bold = args.bold or "",
}
-- Only single-entry types get display override
if not multiEntryTypes[etymkey] and args.entry and args.entry ~= "" then
entryArgs.display = args.entry
end
-- notext: always for multi-entry, otherwise only for idx>1
if multiEntryTypes[etymkey] or idx > 1 then
entryArgs.notext = "1"
end
table.insert(entryLinks, linksModule.mention({ args = entryArgs }))
end
-- Build prefix link
local outputParts = {}
local prefix_link = makeEtymLink(etymtype, nocap_flag)
if prefix_link ~= "" and notext ~= "1" then
table.insert(outputParts, prefix_link .. " deri")
end
table.insert(outputParts, table.concat(entryLinks, " + "))
local output = table.concat(outputParts, " ")
-- Categories
local category = ""
if etymtype ~= "" then
if etymkey == "borrowed" or etymkey == "derived"
or etymkey == "inherited" or etymkey == "pseudo-loan" then
local langname2_nocap = langModule.getLangName({args={lang2, nocap="1"}})
category = U.etymcat(lang1, etymtype, langname2_nocap)
else
category = U.langcat(lang1, etymtype)
end
end
return output .. category
end
return p