local export = {}
local m_template_parser = require("Module:template parser")
local m_links = require("Module:links")
local find_templates = m_template_parser.find_templates
local get_section = require("Module:pages").get_section
function link(term, lang, gloss)
return m_links.full_link {
term = term,
lang = lang,
t = gloss
}
end
local function color_text(text, status)
local color
if status then
color = 'var(--color-content-added, #006400)'
else
color = 'var(--color-content-removed, #8b0000)'
end
return string.format('<span style="color: %s">%s</span>', color, text)
end
local function get_content(title, langname)
local content = mw.title.new(title)
if not content then
return false
end
return get_section(content:getContent(), langname, 2)
end
local function check_was_fwotd(pagename, langcode, langname)
local content = get_content(pagename, langname)
if content == nil then
return false
else
for template in find_templates(content) do
local name = template:get_name()
if name == "was fwotd" then
return true
end
end
end
return false
end
function export.show(frame)
local params = {
= {default = 'und'},
= {default = 'undefined'},
= {},
tr = {},
sc = {},
pos = {},
gloss = {},
cite = {type = "number", default = 0},
pron = {type = "boolean", default = false},
trans = {type = "boolean", default = false},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local langcode = args
local pagename = args
local lang = require("Module:languages").getByCode(langcode)
local langname = lang:getCanonicalName()
local was_fwotd = check_was_fwotd(pagename, langcode, langname)
local icon
local is_good_status = args.cite > 1 or (args.cite >= 1 and args.pron) or (args.cite >= 1 and args.trans) or (args.pron and args.trans)
if is_good_status then
icon = ']'
else
icon = ']'
end
local status = {}
if was_fwotd then
table.insert(status, color_text('Featured', false))
end
if args > 1 then
table.insert(status, color_text('multiple citations', true))
elseif args == 0 then
table.insert(status, color_text('no citations', false))
else
table.insert(status, color_text('citation', true))
end
if args then
table.insert(status, color_text('quote translated', true))
else
table.insert(status, color_text('no translation', false))
end
if args then
table.insert(status, color_text('pronunciation', true))
else
table.insert(status, color_text('no pronunciation', false))
end
local status_text = '(' .. table.concat(status, ', ') .. ')'
-- 7. Assemble and return the final output string.
local result = {
icon,
' ',
langname,
': ',
link(pagename, lang, args),
' ',
status_text
}
return table.concat(result)
end
return export