Dokumentation för denna modul finns på /dok (redigera), /test
Stödja mallarna {{gl-subst-m}}
, {{gl-subst-f}}
och {{gl-subst-mf}}
local gt = require("Modul:grammar-table")
local export = require("Modul:grammar")
local lang_code_param = "gl"
local part_of_speech_param = "subst"
local masculine_templatename = "gl-subst-m"
local feminine_templatename = "gl-subst-f"
local m_and_f_templatename = "gl-subst-mf"
function export._getAcceptedParameters()
return {}
end
function export._getForms(pagename, templatename, args, meta, format)
local last_1 = mw.ustring.sub(pagename, -1, -1)
local last_2 = mw.ustring.sub(pagename, -2, -1)
local second_last_1 = mw.ustring.sub(pagename, -2, -2)
local without_last_1 = mw.ustring.sub(pagename, 1, -2)
local without_last_2 = mw.ustring.sub(pagename, 1, -3)
local ends_with_vowel_or_n = not not mw.ustring.find(last_1, "")
local ends_with_consonant = not not mw.ustring.find(last_1, "")
local ends_with_z = not not mw.ustring.find(last_1, "z")
local ends_with_l = not not mw.ustring.find(last_1, "l")
local ends_with_r = not not mw.ustring.find(last_1, "r")
local ends_with_s = not not mw.ustring.find(last_1, "s")
local ends_with_x = not not mw.ustring.find(last_1, "x")
-- local ends_with_consonant_s = ends_with_x or not not mw.ustring.find(last_2, "")
local ends_with_accent_s = not not mw.ustring.find(last_2, "s")
local function removeAccent(char)
local from_chars = {"á", "é", "í", "ó", "ú"}
local to_chars = {"a", "e", "i", "o", "u"}
for i,from in ipairs(from_chars) do
local to = to_chars
char = mw.ustring.gsub(char, from, to)
end
return char
end
local sing = pagename
local plur = "?"
if ends_with_vowel_or_n then
plur = pagename .. "s"
elseif ends_with_r then
plur = pagename .. "es"
elseif ends_with_z then
plur = without_last_1 .. "ces"
elseif ends_with_l then
--do nothing
elseif last_2 == "és" then
plur = without_last_2 .. "eses"
elseif ends_with_accent_s then
plur = removeAccent(second_last_1) .. "es"
elseif ends_with_x or ends_with_s then
plur = pagename
elseif ends_with_consonant then
plur = pagename .. "s"
end
local forms = {}
forms.sing = args or sing
forms.plur = args or plur
return forms
end
function export._getMeta(pagename, templatename, args)
local last_1 = mw.ustring.sub(pagename, -1, -1)
local last_2 = mw.ustring.sub(pagename, -2, -1)
local ends_with_l = not not mw.ustring.find(last_1, "l")
local ends_with_il = not not mw.ustring.find(last_2, "il")
local gender = ""
if templatename == masculine_templatename then
gender = "m"
elseif templatename == feminine_templatename then
gender = "f"
elseif templatename == m_and_f_templatename then
gender = "mf"
end
local meta = {}
meta.numbered_cells = 2
meta.named_cells = {}
meta.gender = gender
meta.il_ending = ends_with_l
meta.l_ending = ends_with_il
return meta
end
function export._getWikitable(forms, meta)
local number_of_columns = 3
local contains_a_quality_notice = not not meta.quality_notice
local gender = meta.gender
local note = meta.note
local as_first_part = meta.as_first_part
gt.setLanguage(lang_code_param)
local str = gt.getStart(number_of_columns, lang_code_param, part_of_speech_param, contains_a_quality_notice)
.. gt.getRow({'!class="main min"', 'Böjningar av ' .. meta.pagename .. ' ' .. meta.meanings}, {'!', 'Singular'}, {'!', 'Plural'})
if gender == "m" then
str = str .. gt.getRow({'!', 'Maskulinum'}, forms.sing, forms.plur)
elseif gender == "f" then
str = str .. gt.getRow({'!', 'Femininum'}, forms.sing, forms.plur)
elseif gender == "mf" then
str = str .. gt.getRow({'!', 'Maskulinum'}, {'|rowspan="2"', forms.sing}, {'|rowspan="2"', forms.plur})
.. gt.getRow({'!', 'Femininum'})
end
str = str .. gt.getEnd(number_of_columns, note, as_first_part)
return str
end
function export._getCategories(forms, meta)
local ends_with_il_and_plural_is_unclear = meta.il_ending and forms.plural == "?"
local ends_with_l_and_plural_is_unclear = meta.l_ending and forms.plural == "?"
local str = ""
if ends_with_il_and_plural_is_unclear then
str = str .. "]"
elseif ends_with_l_and_plural_is_unclear then
str = str .. "]"
end
return str
end
return export