This is a private module sandbox of Kiril kovachev, for his own experimentation. Items in this module may be added and removed at Kiril kovachev's discretion; do not rely on this module's stability.
local export = {}
local titleObj = mw.title.getCurrentTitle()
local pagename = titleObj.text
local namespace = titleObj.nsText
local find = mw.ustring.find
local length = mw.ustring.len
local trim = mw.text.trim
local split = mw.text.split
local sub, gsub = mw.ustring.sub, mw.ustring.gsub
local match, gmatch = mw.ustring.match, mw.ustring.gmatch
local to_cp, to_char = mw.ustring.codepoint, mw.ustring.char
function export.new(frame, _args) -- _args is used when called from other Lua code
local args = _args or frame:getParent().args
local pos_table = {
= { "Noun", "noun" },
= { "Verb", "verb" },
= { "Verb", "verb form" },
= { "Adjective", "adj" },
= { "Adverb", "pos|adverb" },
= { "Pronoun", "pos|pronoun" },
= { "Proper noun", "pos|proper" },
= { "Phrase", "phrase" },
= { "Interjection", "pos|interjection" },
= { "Conjunction", "pos|conjunction" },
= { "Particle", "pos|particle" },
= { "Preposition", "pos|preposition" },
= { "Suffix", "pos|suffix" },
= { "Prefix", "pos|prefix" },
= { "Affix", "pos|affix" },
= { "Proverb", "pos|proverb" },
= { "Idiom", "pos|idiom" },
= { "Adnominal", "pos|adnominal" },
}
local _pos_table = pos_table; pos_table = {}
for k, v in pairs(_pos_table) do for i in mw.text.gsplit(k, "/") do pos_table = v end end
local result = args and ("===Etymology " .. args .. "===") or "==Bulgarian=="
local hf = args and "=" or ""
if args then
result = result .. "\n{{DEFAULTSORT:" .. args .. "}}"
end
if args then
result = result .. "\n{{wp|lang=bg" .. (args ~= "y" and "|" .. args or "") .. "}}"
end
wp_count = 2
while args do
result = result .. "\n{{wp|lang=bg|" .. args .. "}}"
wp_count = wp_count + 1
end
text = args ~= "" and args or pagename
-- Generate subsection for arguments like alt1, alt2, etc. in a loop.
local function other(class, title, args)
local code, i = "", 2
if args then
code = code .. "\n\n===" .. hf .. title .. hf .. "===\n* {{l|bg|" .. args .. "}}"
while args do
code = code .. "\n* {{l|bg|" .. args .. "}}"
i = i + 1
end
end
return code
end
result = result .. other("alt", "Alternative forms", args)
sortkey = true
--TODO: this etymology section
if args or args or args or args or args or args or args or args or args then
result = result .. "\n\n"
if not args then result = result .. hf .. "===Etymology===" .. hf .. "\n" end
if args then
result = result .. "{{cal|bg|" .. (args or "en") .. (args and "|" .. args or "") .. (args and "|tr=" .. args or "") .. (args and "||" .. args or "") .. (args and "|lit=" .. args or "") .. (args and "|pos=" .. args or "") .. (args and "|g=" .. args or "") .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
if args then
result = result .. ", equivalent to {{pre|bg|" .. args .. "|" .. args .. (args and "|tr1=" .. args or "") .. (args and "|tr2=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t1=" .. args or "") .. (args and "|t2=" .. args or "") .. (args and "|sort=" .. args or "") .. "}}"
elseif args then
result = result .. ", equivalent to {{suf|bg|" .. args .. "|" .. args .. (args and "|tr1=" .. args or "") .. (args and "|tr2=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t1=" .. args or "") .. (args and "|t2=" .. args or "") .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
elseif args then
result = result .. ", equivalent to {{af|bg|" .. args .. (args and "|alt1=" .. args or "") .. (args and "|tr1=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|t1=" .. args or "") .. "|" .. args .. (args and "|alt2=" .. args or "") .. (args and "|tr2=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t2=" .. args or "")
co_count = 3
while args do
result = result .. "|" .. args .. (args and "|alt" .. co_count .. "=" .. args or "") .. (args and "|tr" .. co_count .. "=" .. args or "") .. (args and "|pos" .. co_count .. "=" .. args or "") .. (args and "|t" .. co_count .. "=" .. args or "")
co_count = co_count + 1
end
result = result .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
elseif args then
result = result .. ", equivalent to a {{blend|bg|nocap=y|" .. args .. (args and "|tr1=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|t1=" .. args or "") .. "|" .. args .. (args and "|tr2=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t2=" .. args or "")
bl_count = 3
while args do
result = result .. "|" .. args .. (args and "|tr" .. bl_count .. "=" .. args or "") .. (args and "|pos" .. bl_count .. "=" .. args or "") .. (args and "|t" .. bl_count .. "=" .. args or "")
bl_count = bl_count + 1
end
result = result .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
end
elseif args then
result = result .. "From {{pre|bg|" .. args .. "|" .. args .. (args and "|tr1=" .. args or "") .. (args and "|tr2=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t1=" .. args or "") .. (args and "|t2=" .. args or "") .. (args and "|sort=" .. args or "") .. "}}"
elseif args then
result = result .. "From {{suf|bg|" .. args .. "|" .. args .. (args and "|tr1=" .. args or "") .. (args and "|tr2=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t1=" .. args or "") .. (args and "|t2=" .. args or "") .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
elseif args then
result = result .. "From {{af|bg|" .. args .. (args and "|alt1=" .. args or "") .. (args and "|tr1=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|t1=" .. args or "") .. "|" .. args .. (args and "|alt2=" .. args or "") .. (args and "|tr2=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t2=" .. args or "")
co_count = 3
while args do
result = result .. "|" .. args .. (args and "|alt" .. co_count .. "=" .. args or "") .. (args and "|tr" .. co_count .. "=" .. args or "") .. (args and "|pos" .. co_count .. "=" .. args or "") .. (args and "|t" .. co_count .. "=" .. args or "")
co_count = co_count + 1
end
result = result .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
elseif args then
result = result .. "{{blend|ja|" .. args .. (args and "|tr1=" .. args or "") .. (args and "|pos1=" .. args or "") .. (args and "|t1=" .. args or "") .. "|" .. args .. (args and "|tr2=" .. args or "") .. (args and "|pos2=" .. args or "") .. (args and "|t2=" .. args or "")
bl_count = 3
while args do
result = result .. "|" .. args .. (args and "|tr" .. bl_count .. "=" .. args or "") .. (args and "|pos" .. bl_count .. "=" .. args or "") .. (args and "|t" .. bl_count .. "=" .. args or "")
bl_count = bl_count + 1
end
result = result .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
elseif args then
result = result .. "{{bor+|bg|" .. (args or "en") .. (args and "|" .. args or "") .. (args and "|tr=" .. args or "") .. (args and "||" .. args or "") .. (args and "|lit=" .. args or "") .. (args and "|pos=" .. args or "") .. (args and "|g=" .. args or "") .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
elseif args then
result = result .. "{{lbor|bg|" .. (args or "grc") .. (args and "|" .. args or "") .. (args and "|tr=" .. args or "") .. (args and "||" .. args or "") .. (args and "|lit=" .. args or "") .. (args and "|pos=" .. args or "") .. (args and "|g=" .. args or "") .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
else
result = result .. (args or
("From {{der|bg|" .. (args or "en") .. (args and "|" .. args or "") .. (args and "|tr=" .. args or "") .. (args and "||" .. args or "") .. (args and "|lit=" .. args or "") .. (args and "|pos=" .. args or "") .. (args and "|g=" .. args or "") .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"))
end
end
-- Add pronunciation
result = result .. "\n\n" .. hf .. "===Pronunciation===" .. hf .. "\n* {{bg-IPA" .. (args ~= "" and "|" .. gsub(text, '%^', '') or "" .. "}}")
acc_count = 2
while args do
result = result .. "\n* {{bg-IPA" .. args .. "}}"
acc_count = acc_count + 1
end
if args then
result = result .. (args and "{{hmp|bg|" .. args or "")
hmp_count = 2
while args do
result = result .. "|" .. args
hmp_count = hmp_count + 1
end
result = result .. "}}"
end
if args then
args = args .. "\n#" .. args
end
local eg_count = 2
while args do
args = args .. "\n#" .. args
eg_count = eg_count + 1
end
local function add_pos(header, template_name, def)
result = result .. "\n\n" .. hf .. "===" .. header .. "===" .. hf .. "\n{{bg-" .. template_name ..
(args ~= "" and "|" .. text or "")
if template_name == "verb" then
result = result .. (args and "|" .. args or "")
if args then
ac = (args == "pf") and "impf" or "pf"
result = result .. "|" .. ac .. "=" .. args
end
end
if template_name == "noun" then
result = result .. (args and "|" .. args or "")
result = result .. (args and "|adj=" .. args)
end
result = result .. "}}"
result = result .. "\n\n# " .. (def or "{{rfdef|bg}}")
if header == "Adjective" or header == "Noun" then
a_or_n = (header == "Adjective") and "a" or "n"
result = result .. "\n\n" .. hf .. "====Declension====" .. hf .. "\n"
result = result .. "{{bg-" .. a_or_n .. "decl|" .. text .. "<" .. (args or "") .. ">"
end
if header == "Verb" then
result = result .. "\n\n" .. hf .. "====Conjugation====" .. hf .. "\n"
result = result .. "{{bg-conj" .. "|" .. text .. "<" .. (args or "") .. ">"
end
end
if not pos_table] then error("The POS code " .. args .. " is not valid. See ] for a list of valid POS.") end
add_pos(pos_table], pos_table], args)
if args then
result = result .. "\n\n" .. hf .. "====Usage notes====" .. hf .. "\n* " .. args
end
result = result .. other("syn", "=Synonyms=", args)
result = result .. other("ant", "=Antonyms=", args)
result = result .. other("der", "=Derived terms=", args)
result = result .. other("rel", "=Related terms=", args)
if args then
if not pos_table] then error("The POS code " .. args .. " is not valid. See ] for a list of valid POS.") end
add_pos(pos_table], pos_table], args)
if args then
result = result .. "\n\n" .. hf .. "====Usage notes====" .. hf .. "\n* " .. args
end
result = result .. other("Syn", "=Synonyms=", args)
result = result .. other("Ant", "=Antonyms=", args)
result = result .. other("Der", "=Derived terms=", args)
result = result .. other("Rel", "=Related terms=", args)
end
if args then
if not pos_table] then error("The POS code " .. args .. " is not valid. See ] for a list of valid POS.") end
add_pos(pos_table], pos_table], args)
if args then
result = result .. "\n\n" .. hf .. "====Usage notes====" .. hf .. "\n* " .. args
end
result = result .. other("SYN", "=Synonyms=", args)
result = result .. other("ANT", "=Antonyms=", args)
result = result .. other("DER", "=Derived terms=", args)
result = result .. other("REL", "=Related terms=", args)
end
if args then error("this template only supports up to three POS, please ask someone to expand me") end
result = result .. other("ana", "Anagrams", args)
result = result .. other("also", "See also", args)
if args ~= "n" then
result = result .. "\n\n===References===\n"
if args == "1" then
result = result .. "* {{R:bg:RBE}}"
elseif args == "2" then
result = result .. "* {{R:bg:RBE2}}"
else
result = result .. "* {{R:bg:RBE}}\n* {{R:bg:RBE2}}"
end
end
if args then
result = result .. "\n\n{{cln|bg|" .. args
cn_count = 2
while args do
result = result .. "|" .. args
cn_count = cn_count + 1
end
result = result .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
end
if args then
result = result .. (args and "\n" or "\n\n") .. "{{C|bg|" .. args
ct_count = 2
while args do
result = result .. "|" .. args
ct_count = ct_count + 1
end
result = result .. (args and "" or args and "|sort=" .. args or sortkey or "") .. "}}"
end
return result
end
return export