local languages = mw.loadData("Module:languages")
local utilities = require("Module:useful stuff")
local links = require("Module:links")
local export = {}
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.main(frame)
local args = frame:getParent().args
PAGENAME = mw.title.getCurrentTitle().text
NAMESPACE = mw.title.getCurrentTitle().nsText
local ret = ""
-- Language code
local lang = args or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
local langinfo = languages or error("The language code \"" .. lang .. "\" is not valid.")
local alt = args; if alt == "" then alt = nil end
local translit = args; if translit == "" then translit = nil end
if not translit then
translit = utilities.translit(lang, alt or PAGENAME)
end
local g1 = args
if not g1 or g1 == "" then
g1 = args
if g1 == "" then g1 = nil end
end
local g2 = args; if g2 == "" then g2 = nil end
local g3 = args; if g3 == "" then g3 = nil end
local script = args; if script == "" then script = nil end
if not script then
script = languages.scripts
end
local class = "headword"
if script then
class = class .. " " .. script
end
ret = utilities.annotate(head or PAGENAME, lang, "strong", class, translit, nil, {g1, g2, g3}, frame)
for i = 3, 22, 2 do
if args then
if i ~= 3 then
if args ~= "or" then
ret = ret .. ","
end
ret = ret .. " "
end
ret = ret .. "''" .. args .. "''"
if args then
ret = ret .. " " .. links.annotated_link(args, nil, lang, "strong", script)
end
end
end
-- Categories
if NAMESPACE == "" then
local categories = {}
local pos = args; if pos == "" then pos = nil end
if pos then
-- Make the plural form of the part of speech
if pos:find("x$") then
pos = pos .. "es"
elseif pos ~= "punctuation" or pos ~= "phrasebook" then
pos = pos .. "s"
end
table.insert(categories, langinfo.names .. " " .. pos)
end
local cat2 = args; if cat2 == "" then cat2 = nil end
if cat2 then
table.insert(categories, langinfo.names .. " " .. cat2)
end
local cat3 = args; if cat3 == "" then cat3 = nil end
if cat3 then
table.insert(categories, langinfo.names .. " " .. cat3)
end
-- Add the categories with the appropriate sort key
local sort_key = args; if sort_key == "" then sort_key = nil end
for key, cat in ipairs(categories) do
ret = ret .. "]"
end
end
return ret
end
return export