Module:form of: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) mNo edit summary |
TheNightAvl (talk | contribs) m (Added slash split functionality) |
||
Line 6: | Line 6: | ||
local function make_labels(inflections) | local function make_labels(inflections) | ||
local out = {} | local out = {} | ||
-- split parameters at / and , | |||
while inflections[it] do | |||
if mw.ustring.find(inflections[it], "^[^,]+,%s.+") then | |||
local before = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%1") | |||
local after = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%2") | |||
inflections[it] = before | |||
table.insert(inflections, it + 1, after) | |||
end | |||
if mw.ustring.find(inflections[it], "^[^/]+/.+") then | |||
local before = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%1") | |||
local after = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%2") | |||
inflections[it] = before | |||
table.insert(inflections, it + 1, after) | |||
table.insert(inflections, it + 1, "/") | |||
end | |||
it = it + 1 | |||
end | |||
for i, inflection in ipairs(inflections) do | for i, inflection in ipairs(inflections) do | ||
if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end | if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end |
Revision as of 06:03, 10 December 2023
local export = {}
local m_links = require("Module:links")
local m_data = mw.loadData("Module:form of/data")
local function make_labels(inflections)
local out = {}
-- split parameters at / and ,
while inflections[it] do
if mw.ustring.find(inflections[it], "^[^,]+,%s.+") then
local before = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%1")
local after = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%2")
inflections[it] = before
table.insert(inflections, it + 1, after)
end
if mw.ustring.find(inflections[it], "^[^/]+/.+") then
local before = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%1")
local after = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%2")
inflections[it] = before
table.insert(inflections, it + 1, after)
table.insert(inflections, it + 1, "/")
end
it = it + 1
end
for i, inflection in ipairs(inflections) do
if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end
local l = m_data.labels[inflection]
if l then
local text = l.label or inflection
if l.glossary then
table.insert(out, "[[Appendix:Glossary#" .. (type(l.glossary) == "string" and l.glossary or text) .. "|" .. text .. "]]")
else
table.insert(out, text)
end
else
table.insert(out, inflection)
end
if inflection ~= "/" and inflections[i+1] ~= "/" and inflections[i+1] then
table.insert(out, " ")
end
end
return table.concat(out)
end
function export.make_form_of(data)
local label
local link = m_links.full_link(data, "term")
if data.inflection then
label = make_labels(data.inflection)
else
label = data.form or "alternative form"
end
return '<span class="form-of">' .. label .. ' of ' .. link .. '</span>'
end
function export.list_form(data)
local label
if data.inflection then
label = make_labels(data.inflection)
else
label = data.form or "alternative form"
end
return '<span class="form-of">' .. label .. '</span>'
end
return export