Back-end for {{new}}
.
-- Fork of Module:bo-common to allow the creation of entries by substituting a template; UNDER CONSTRUCTION
local m_str_utils = require("Module:string utilities")
local codepoint = m_str_utils.codepoint
local gsub = m_str_utils.gsub
local len = m_str_utils.len
local match = m_str_utils.match
local sub = m_str_utils.sub
local find = m_str_utils.find
local u = m_str_utils.char
local upper = m_str_utils.upper
local lower = m_str_utils.lower
local export = {}
function export.new(frame)
local title = mw.title.getCurrentTitle().text
local parent_args = frame:getParent().args
local params = {
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
}
local args = require("Module:parameters").process(parent_args, params)
local output
-- Gets the language name if a code is provided, but can also auto-detect the language on Reconstruction pages.
-- Sticks {{reconstructed}} atop the language L2 header if the page is in the Reconstruction namespace.
local fullpagename = mw.title.getCurrentTitle().fullText
local m_languages = require("Module:languages")
local langcode
local langname
local lang
local l2
if find(fullpagename, "Reconstruction:") then
langname = match(fullpagename, "Reconstruction:(.+)/")
lang = m_languages.getByCanonicalName(langname)
langcode = lang:getCode()
l2 = "{{reconstructed}}\n" .. "==" .. langname .. "=="
else
langcode = args
lang = m_languages.getByCode(langcode)
langname = lang:getCanonicalName()
l2 = "==" .. langname .. "=="
end
local output = l2
-- Gets the appropriate part-of-speech header
local function genTitle(text)
local pos_title = {
= "Noun", = "Noun", = "Proper noun", = "Proper noun", = "Pronoun",
= "Verb", = "Verb", = "Adjective", = "Adjective", = "Adverb",
= "Preposition", = "Postposition", = "Conjunction",
= "Particle", = "Suffix",
= "Proverb", = "Idiom", = "Phrase", = "Interjection", = "Interjection",
= "Classifier", = "Classifier", = "Numeral", = "Abbreviation", = "Determiner"
};
return pos_title or upper(sub(text, 1, 1)) .. sub(text, 2, -1)
end
local pos_l3 = genTitle(args)
-- Etymology
etym = args
if etym then
output = output .. "\n\n===Etymology===\n" .. etym
end
-- Pronunciation. If a template is the input, it should return that template; raw IPA input is wrapped with {{IPA}}
ipa = args or args
if ipa then
output = output .. "\n\n===Pronunciation===\n"
if find(ipa, "{{") then
output = output .. "* " .. ipa
else
output = output .. "* {{IPA|" .. langcode .. "|" .. ipa .. "}}"
end
end
-- Part-of-speech header and head
output = output .. "\n\n===" .. pos_l3 .. "===\n"
local head = "{{head|" .. langcode .. "|" .. lower(pos_l3) .. "}}"
local alt = args
if alt then
head = gsub(head, "}}$", "|head=" .. alt .. "}}")
end
output = output .. head .. "\n\n"
-- Handles the definition.
-- If the parameter input has no hashtag, this loop is supposed to insert one.
-- If no definition is provided, {{rfdef}} should be returned
local def = args
if def then
if find(def, "^# ") then
output = output .. def
else
output = output .. "# " .. def
end
else
output = output .. "# {{rfdef|" .. langcode .. "}}"
end
-- Descendants
local desc = args
if desc then
output = output .. "\n\n====Descendants====\n" .. desc
end
-- Further reading
local fr = args
if fr then
output = output .. "\n\n===Further reading===\n"
output = output .. "* " .. fr
end
return output
end
return export