Modul:ca-subst
Utseende
Dokumentation för denna modul finns på /dok (redigera), /test
Syfte
[redigera]Stödja mallarna {{ca-subst-m}}
, {{ca-subst-f}}
, {{ca-subst-mf}}
och {{ca-subst-var}}
local gt = require("Modul:grammar-table")
local export = require("Modul:grammar")
local lang_code_param = "ca"
local part_of_speech_param = "subst"
local masculine_templatename = "ca-subst-m"
local feminine_templatename = "ca-subst-f"
local m_and_f_templatename = "ca-subst-mf"
local var_templatename = "ca-subst-var-test"
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 last_3 = mw.ustring.sub(pagename, -3, -1)
local last_4 = mw.ustring.sub(pagename, -4, -1)
local without_last_1 = mw.ustring.sub(pagename, 1, -2)
local without_last_2 = mw.ustring.sub(pagename, 1, -3)
local without_last_3 = mw.ustring.sub(pagename, 1, -4)
local without_last_4 = mw.ustring.sub(pagename, 1, -5)
local vowel = "[aeiouàèéíòóú]"
local consonant = "[bcçdfghjklmnpqrstvwxyz]"
local ends_with_ca = not not mw.ustring.find(last_2, "ca")
local ends_with_cedilj_a = not not mw.ustring.find(last_2, "ça")
local ends_with_ga = not not mw.ustring.find(last_2, "ga")
local ends_with_gua_or_qua = not not mw.ustring.find(last_3, "[gq]ua")
local ends_with_ja = not not mw.ustring.find(last_2, "ja")
local ends_with_a = not not mw.ustring.find(last_1, "a")
local ends_with_accented_os = not not mw.ustring.find(last_3, "[bdf]ós")
local ends_with_accent_s = not not mw.ustring.find(last_3, "[bcçdfghjklmnpqrstuvwxyz][àèéíòóú]s")
local ends_with_s_or_x = not not mw.ustring.find(last_1, "[sxz]")
local ends_with_consonant = not not mw.ustring.find(last_1, "[bcçdfghjklmnpqrstvwxyz]")
local ends_with_other_vowel = not not mw.ustring.find(last_1, "[eiou]")
local ends_with_accent = not not mw.ustring.find(last_1, "[àèéíòóú]")
local ends_with_accent_con_ic = not not mw.ustring.find(last_4, "[àèéíòóú][bcçdfghjklmnpqrstvwxyz]ic")
local has_irregular_comparation = meta.irreg_comp
local function removeAccent(char)
local from_chars = {"à", "è", "é", "í", "ò", "ó", "ú"}
local to_chars = {"a", "e", "e", "i", "o", "o", "u"}
for i,from in ipairs(from_chars) do
local to = to_chars[i]
char = mw.ustring.gsub(char, from, to)
end
return char
end
local sing = pagename
local plur = "?"
if ends_with_ca then
plur = without_last_2 .. "ques"
elseif ends_with_cedilj_a then
plur = without_last_2 .. "ces"
elseif ends_with_ga then
plur = without_last_1 .. "ues"
elseif ends_with_gua_or_qua then
plur = without_last_2 .. "ües"
elseif ends_with_ja then
plur = without_last_2 .. "ges"
elseif ends_with_a then
plur = without_last_1 .. "es"
elseif ends_with_accent then
plur = without_last_1 .. removeAccent(last_1) .. "ns"
elseif ends_with_accented_os then
plur = without_last_2 .. removeAccent(last_2) .. "sos"
elseif ends_with_accent_s then
plur = without_last_2 .. removeAccent(last_2) .. "os"
elseif last_2 == "os" then
plur = pagename .. "sos"
elseif ends_with_s_or_x then
plur = pagename .. "os"
elseif last_1 == "ç" then
plur = pagename .. "os"
elseif last_3 == "aig" then
plur = without_last_2 .. "jos"
elseif last_2 == "ig" then
plur = pagename .. "s, " .. without_last_1 .. "tjos"
elseif ends_with_consonant then
plur = pagename .. "s"
elseif mw.ustring.find(last_1, consonant) then
plur = pagename .. "s"
elseif mw.ustring.find(last_1, vowel) then
plur = pagename .. "s"
end
local forms = {}
forms.sing = args[1] or sing
forms.plur = args[2] 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 .. "[[Kategori:Wiktionary:ca-subst/Pluralform saknas (-ís eller -iles?)]]"
elseif ends_with_l_and_plural_is_unclear then
str = str .. "[[Kategori:Wiktionary:ca-subst/Pluralform saknas (-is eller -les?)]]"
end
return str
end
return export