Module:form of: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
local m_links = require("Module:links") | local m_links = require("Module:links") | ||
local m_data = mw.loadData("Module:form of/data") | local m_data = mw.loadData("Module:form of/data") | ||
local function pluralize(word) | |||
local ending = mw.ustring.sub(word, -1) | |||
if ending == "h" and mw.ustring.sub(word, -2, -1) == "s" then ending = "sh" end | |||
if ending == "s" or ending == "z" or ending == "x" or ending == "sh" then | |||
return word .. "es" | |||
end | |||
return word .. "s" | |||
end | |||
local function make_labels(inflections, language) | local function make_labels(inflections, language) | ||
Line 38: | Line 47: | ||
if text == "verbal noun" then | if text == "verbal noun" then | ||
glosslink = glosslink .. "[[Category:" .. language.name .. " verbal nouns]]" | glosslink = glosslink .. "[[Category:" .. language.name .. " verbal nouns]]" | ||
end | end | ||
table.insert(out, glosslink) | table.insert(out, glosslink) | ||
Line 59: | Line 65: | ||
local label | local label | ||
local link = m_links.full_link(data, "term") | local link = m_links.full_link(data, "term") | ||
local note = data.note | |||
if note then | |||
if mw.ustring.find(note, "^%P") then | |||
note = " " .. note | |||
end | |||
else | |||
note = "" | |||
end | |||
if data.inflection then | if data.inflection then | ||
label = make_labels(data.inflection, data.language) | label = make_labels(data.inflection, data.language) | ||
Line 64: | Line 78: | ||
label = m_labels.make_labels(data.language, {[1] = data.form or "alternative form"}, data.nocat, true) | label = m_labels.make_labels(data.language, {[1] = data.form or "alternative form"}, data.nocat, true) | ||
end | end | ||
return '<span class="form-of">' .. label .. ' of ' .. link .. '</span>' | return '<span class="form-of">' .. label .. ((data.post and (" ".. data.post)) or "") .. ' of ' .. link .. note .. '</span>' | ||
end | end | ||
Latest revision as of 12:24, 17 August 2024
local export = {}
local m_labels = require("Module:labels")
local m_links = require("Module:links")
local m_data = mw.loadData("Module:form of/data")
local function pluralize(word)
local ending = mw.ustring.sub(word, -1)
if ending == "h" and mw.ustring.sub(word, -2, -1) == "s" then ending = "sh" end
if ending == "s" or ending == "z" or ending == "x" or ending == "sh" then
return word .. "es"
end
return word .. "s"
end
local function make_labels(inflections, language)
local out = {}
if inflections[1] == nil then return "inflection" end
-- split parameters at / and ,
local it = 1
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
glosslink = "[[Appendix:Glossary#" .. (type(l.glossary) == "string" and l.glossary or text) .. "|" .. text .. "]]"
if text == "verbal noun" then
glosslink = glosslink .. "[[Category:" .. language.name .. " verbal nouns]]"
end
table.insert(out, glosslink)
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")
local note = data.note
if note then
if mw.ustring.find(note, "^%P") then
note = " " .. note
end
else
note = ""
end
if data.inflection then
label = make_labels(data.inflection, data.language)
else
label = m_labels.make_labels(data.language, {[1] = data.form or "alternative form"}, data.nocat, true)
end
return '<span class="form-of">' .. label .. ((data.post and (" ".. data.post)) or "") .. ' of ' .. link .. note .. '</span>'
end
function export.list_form(data)
local label
if data.inflection then
label = make_labels(data.inflection, data.language)
else
label = data.form or "alternative form"
end
return '<span class="form-of">' .. label .. '</span>'
end
return export