Module:mg-noun: Difference between revisions

362 bytes removed ,  12 September 2021
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local export = {}
local m_u = require('Module:utilities')
local m_data = require('Module:mg-noun/data')
local sub = mw.ustring.sub
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit


local m_utils = require("Module:utilities")
local m_data = require('Module:mg-noun/data')
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local NAMESPACE = mw.title.getCurrentTitle().nsText


local lang = require("Module:languages").getByCode("cel-gal")
local genders = {["m"] = "masculine", ["f"] = "feminine"}
 
local export = {}


local function detect_decl(word, class)
local function detect_decl(word)
local last = sub(word, 1, -2)
local last = sub(word, 1, -2)
if class then
if word:match("[aeor]$") then
return class, {last}
return mw.ustring.upper(last)
elseif word:match("[aeor]$") then
return mw.ustring.upper(last), {last}
elseif word:match("n$") then
elseif word:match("n$") then
return "participle", {last}
return "participle"
end
end
return "consonant", {last}
end
end


Line 31: Line 32:
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
local numbers = nil
local numbers = {}
local decl = {}
local decl = {}
local word = parent_args.word or NAMESPACE == "Template" and "mazer" or PAGENAME
local g = NAMESPACE == "Template" and "f" or parent_args["g"]
local word = NAMESPACE == "Template" and "mazer" or parent_args["word"] or PAGENAME
local args = {}
local args = {}
local decl_type = ""
local decl_type = parent_args[1] or parent_args["decl"] or detect_decl(word)
 
if g ~= "m" and g ~= "f" then error("Unknown gender: it must be either ‘i’ or ‘a’") end
if not m_data[word] then
if not m_data[word] then
if frame.args.decl then
decl_type = frame.args.decl
else
if parent_args.c and parent_args[1] then
decl_type = parent_args.c
numbers = {parent_args[1]}
else
decl_type, numbers = detect_decl(word, parent_args.c)
end
end
if NAMESPACE == "Template" then decl_type = "R" end
if not decl_type then
--[[if not decl_type then
error("Unknown declension '" .. decl_type .. "'")
error("Unknown declension '" .. decl_type .. "'")
end]]
end
args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true)
args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true)
Line 66: Line 58:
local data = {forms = {}, categories = {}}
local data = {forms = {}, categories = {}}
data.head = parent_args["head"] or nil
data.head = parent_args["head"] or word
data.proper = parent_args["proper"] and true or false
data.proper = parent_args["proper"] and true or false
data.nocat = parent_args["nocat"] and true or false
data.nocat = parent_args["nocat"] and true or false
data.nopl = parent_args["nopl"] and true or false
data.g = genders[g]
data.g = NAMESPACE == "Template" and "feminine" or parent_args["g"]
data.decl_type = decl_type
data.pos = parent_args["pos"] or "nouns"
-- Generate the forms
-- Generate the forms
if m_data[word] then
if m_data[word] then
m_data[word](parent_args, data)
m_data[word](parent_args, data)
else
else
m_data[decl_type](args, data)
m_data[decl_type](args, data)
end
end
 
-- Make the table
-- make the table
return make_table(data)
return make_table(data)
end
end
Line 142: Line 135:
<div class="mw-collapsible-content" style="font-size: 100%;">
<div class="mw-collapsible-content" style="font-size: 100%;">
]=]
]=]
 
local wikicode = [=[
local wikicode = [=[
{| class="bluetable" border="1px solid #000000" style="border-collapse:collapse; background:#fafafa; text-align:center; width:100%"
{| class="bluetable" border="1px solid #000000" style="border-collapse:collapse; background:#fafafa; text-align:center; width:100%"
|-
|-
Line 152: Line 144:
]=] .. make_cases(data) .. [=[
]=] .. make_cases(data) .. [=[
|}</div></div>]=]
|}</div></div>]=]
local sgwik = [=[
{| class="bluetable" border="1px solid #000000" style="border-collapse:collapse; background:#fafafa; text-align:center; width:100%"
return gsub(navframe .. wikicode, "{{{([a-z0-9_]+)}}}", repl)
|-
  .. (not data.nocat and m_u.format_categories(data.categories, lang) or "")
! &nbsp;
! Singular
]=] .. make_cases(data) .. [=[
|}</div></div>]=]
 
 
return gsub(navframe .. (data.nopl and sgwik or wikicode), "{{{([a-z0-9_]+)}}}", repl)
  .. (not data.nocat and m_utils.format_categories(data.categories, lang) or "")
end
end


return export
return export