Module:qlu-nouns: Difference between revisions

Jump to navigation Jump to search
m
more testing
m (test)
m (more testing)
Line 194: Line 194:
end
end


local function show_form(form, data, branch)
local function show_form(form, data)
local function convert_word(form, branch)
local function convert_word(form)
if mw.ustring.find(form, "{{{") then
if mw.ustring.find(form, "{{{") then
return form
return form
else
else
return m_vl_translit.convert_words(form, branch)
return m_vl_translit.convert_words(form)
end
end
end
end
Line 209: Line 209:
if title:inNamespace("") then
if title:inNamespace("") then
return m_links.full_link({lang = lang, alt = convert_word(form, branch), term = form})
return m_links.full_link({lang = lang, alt = convert_word(form), term = form})
else
else
return m_links.full_link({lang = lang, alt = convert_word(form, branch), term = "*" .. form})
return m_links.full_link({lang = lang, alt = convert_word(form), term = "*" .. form})
end
end
end
end


local function make_case(data, wikicode, case, branch)
local function make_case(data, wikicode, case)
local case_short = cases[case].short_form
local case_short = cases[case].short_form
table.insert(wikicode, '|- class="vsHide"\n')
table.insert(wikicode, '|- class="vsHide"\n')
table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';" | ' .. cases[case].link .. '\n')
table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';" | ' .. cases[case].link .. '\n')
table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_form(data.forms[case_short .. '-sg'], data, branch) .. '\n')
table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_form(data.forms[case_short .. '-sg'], data) .. '\n')
table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_form(data.forms[case_short .. '-pl'], data, branch) .. '\n')
table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_form(data.forms[case_short .. '-pl'], data) .. '\n')
end
end


local function make_table(data, branch)
local function make_table(data)
local wikicode = {'{| class="prettytable inflection-table vsSwitcher" data-toggle-category="inflection"\n'}
local wikicode = {'{| class="prettytable inflection-table vsSwitcher" data-toggle-category="inflection"\n'}
table.insert(wikicode, '! colspan="5" class="vsToggleElement" style="text-align:left;min-width: 25em;background:#' ..
table.insert(wikicode, '! colspan="5" class="vsToggleElement" style="text-align:left;min-width: 25em;background:#' ..
data.latincolour[1] .. '" | ')
data.latincolour[1] .. '" | ')
table.insert(wikicode, branch_links[branch] .. ' declension of #head\n')


make_headers(data, wikicode)
make_headers(data, wikicode)
make_case(data, wikicode, "nominative", branch)
make_case(data, wikicode, "nominative")
make_case(data, wikicode, "genitive", branch)
make_case(data, wikicode, "genitive")
make_case(data, wikicode, "dative", branch)
make_case(data, wikicode, "dative")
make_case(data, wikicode, "accusative", branch)
make_case(data, wikicode, "accusative")


table.insert(wikicode, "|}")
table.insert(wikicode, "|}")
Line 239: Line 238:
return table.concat(wikicode)
return table.concat(wikicode)
end
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local parent_args = frame:getParent().args
local decl_type = (frame.args["decl"] or parent_args["decl"]) or "a"
if not decls[decl_type] then
error("Unknown declension type '" .. decl_type .. "'")
end
local data = {forms = {}}
data.head = parent_args["head"] or nil
data.latincolour = {
frame:expandTemplate({title = "Latincolour1"}),
frame:expandTemplate({title = "Latincolour2"}),
frame:expandTemplate({title = "Latincolour3"}),
}
local args = require("Module:parameters").process(parent_args, decls[decl_type].params, true)
if not args[1] then
setmetatable(args, {__index = function(self, key)
return "{{{" .. key .. "}}}"
end
})
end
-- Generate the forms
decls[decl_type](args, data)
data["decl"] = decl_type
-- Make the table
t = decl_names[data.decl] .. '.\n\n'
if parent_args.family then
t = t .. make_table(data, parent_args.family)
if parent_args.family2 then
t = t .. "\n" .. make_table(data, parent_args.family2)
end
else
t = t .. make_table(data, "It-W") .. "\n" .. make_table(data, "E") .. "\n" .. make_table(data, "S")
end
if title:inNamespace("") then
t = mw.ustring.gsub(t, "#head", m_links.full_link({lang = lang, alt = data.forms["nom-sg"]}, "term"))
else
t = mw.ustring.gsub(t, "#head", m_links.full_link({lang = lang, alt = "*" .. data.forms["nom-sg"]}, "term"))
end
return t
end
return export
1,849

edits

Navigation menu