This module provides the back-end for all Serbo-Croatian headword-line templates. It provides them with the basic functionality of |head=
and |tr=
and categorization. It also provides extended functionality for {{sh-adjective}}
, {{sh-letter}}
, {{sh-noun}}
, and {{sh-verb}}
.
local export = {}
local lang = require("Module:languages").getByCode("sh")
local function otherscript(inflections, args)
local title = mw.title.getCurrentTitle()
local sc = lang:findBestScript(title.subpageText)
local other_sc
if sc:getCode() == "Latn" then
other_sc = "Cyrl"
elseif sc:getCode() == "Cyrl" then
other_sc = "Latn"
end
other_sc = require("Module:scripts").getByCode(other_sc)
local inflection = {label = other_sc:getCanonicalName() .. " spelling"}
local heads = args
if #heads == 0 then
heads = {title.subpageText}
end
if args == "-" then
inflection.label = "not attested in " .. other_sc:getCanonicalName() .. " spelling"
else
for i, head in ipairs(heads) do
local tr = args
if not tr then
tr = require("Module:sh-translit").tr(require("Module:links").remove_links(head), "sh", sc:getCode())
end
table.insert(inflection, {term = tr, sc = other_sc})
end
end
table.insert(inflections, inflection)
end
local function glossary_link(entry, text)
text = text or entry
return "]"
end
function export.basic(frame)
local params = {
= {list = true},
= {list = true, allow_holes = true},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = frame.args, categories = {}, heads = args, genders = {}, inflections = {}}
otherscript(data.inflections, args)
return require("Module:headword").full_headword(data)
end
function export.adjective(frame)
local params = {
= {list = true},
= {list = true},
= {list = true},
= {list = true},
= {list = true, allow_holes = true},
= {type = "boolean"}
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "adjectives", categories = {}, heads = args, genders = {}, inflections = {}}
otherscript(data.inflections, args)
-- Add parameters
local param_list = {
{"def", "definite"},
{"comp", "comparative"},
{"adv", "derived adverb"},
}
if args then
table.insert(data.inflections, {label = glossary_link("indeclinable")})
end
for _, val in pairs(param_list) do
local param_name, label = unpack(val)
local forms = args
if forms then
forms.label = (param_name == "adv") and label or glossary_link(label)
table.insert(data.inflections, forms)
end
end
return require("Module:headword").full_headword(data)
end
local gender_cats = {
= "masculine",
= "feminine",
= "neuter",
= "masculine",
= "feminine",
= "neuter",
}
function export.letter(frame)
local params = {
= {},
= {},
= {list = true},
= {list = true, allow_holes = true},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "letters", categories = {}, heads = args, genders = {}, inflections = {}}
if args then
table.insert(data.inflections, {label = "lower case", nil})
table.insert(data.inflections, {label = "upper case", args})
elseif args then
table.insert(data.inflections, {label = "upper case", nil})
table.insert(data.inflections, {label = "lower case", args})
end
otherscript(data.inflections, args)
return require("Module:headword").full_headword(data)
end
function export.noun(frame)
local params = {
= {list = true, default = "?"},
= {list = true},
= {list = true, allow_holes = true},
= {list = true},
= {list = true},
= {list = true},
= {list = true},
= {list = true},
= {type = "boolean"}
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "nouns", categories = {}, heads = args, genders = args, inflections = {}}
for i, gender in ipairs(data.genders) do
if gender_cats then
table.insert(data.categories, lang:getCanonicalName() .. " " .. gender_cats .. " nouns")
else
data.genders = "?"
end
end
otherscript(data.inflections, args)
-- Add parameters
local param_list = {
{"f", "feminine"},
{"m", "masculine"},
{"dim", "diminutive"},
{"aug", "augmentative"},
{"adj", "relational adjective"},
}
if args then
table.insert(data.inflections, {label = glossary_link("indeclinable")})
end
for _, val in pairs(param_list) do
local param_name, label = unpack(val)
local forms = args
if forms then
forms.label = glossary_link(label)
table.insert(data.inflections, forms)
end
end
return require("Module:headword").full_headword(data)
end
function export.propernoun(frame)
local params = {
= {list = true, default = "?"},
= {list = true},
= {list = true},
= {list = true, allow_holes = true},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "proper nouns", categories = {}, heads = args, genders = args, inflections = {}}
for i, gender in ipairs(data.genders) do
if gender_cats then
table.insert(data.categories, lang:getCanonicalName() .. " " .. gender_cats .. " nouns")
else
data.genders = "?"
end
end
otherscript(data.inflections, args)
-- Add parameters
local param_list = {
{"adj", "relational adjective"},
}
for _, val in pairs(param_list) do
local param_name, label = unpack(val)
local forms = args
if forms then
forms.label = glossary_link(label)
table.insert(data.inflections, forms)
end
end
return require("Module:headword").full_headword(data)
end
function export.verb(frame)
local params = {
= {},
= {list = true},
= {list = true, allow_holes = true},
= {list = true},
= {list = true}
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "verbs", categories = {}, heads = args, genders = {}, inflections = {}}
if args == "impf" or args == "pf" then
table.insert(data.genders, args)
elseif args == "impf-pf" or args == "pf-impf" or args == "dual" or args == "ip" then
table.insert(data.genders, "impf")
table.insert(data.genders, "pf")
else
table.insert(data.genders, "?")
end
otherscript(data.inflections, args)
--add perfective equivalent
local pf = args
if #pf > 0 then
pf.label = "perfective"
table.insert(data.inflections, pf)
end
--add imperfective equivalent
local impf = args
if #impf > 0 then
impf.label = "imperfective"
table.insert(data.inflections, impf)
end
return require("Module:headword").full_headword(data)
end
return export