This is a private module sandbox of Crom daba, for his own experimentation. Items in this module may be added and removed at Crom daba's discretion; do not rely on this module's stability.
local export = {}
local m_translit = require("Module:sh-translit")
local m_headword = require("Module:headword")
local m_links = require("Module:links")
local m_sc = require("Module:scripts")
local lang = require("Module:languages").getByCode("sh")
local lang_canon = lang:getCanonicalName()
function map(f, xs)
local s = {}
for k,v in pairs(xs) do s = f(v) end
return s
end
local function sh_yat(yat)
local s
if yat == 'i' then s = "Ikavian"
elseif yat == 'e' then s = "Ekavian"
elseif yat == 'ije' then s = "Ijekavian"
elseif yat == 'e+ije' or 'ije+e' then s = "Ekavian and Ijekavian"
end
return "<small> (''" .. s .. "'') </small>"
end
local function head (sc,heads, genders, inflections, categories, sort_key, force_cat_output, yat)
if #heads == 0 then
local WORDBREAKCHARS = "(+)"
local EXCLUDECHARS = "(+)" -- workaround for excluding characters from the above
local contains_words = false
mw.ustring.gsub(default_head, WORDBREAKCHARS, function(b)
contains_words = contains_words or mw.ustring.match(b, "^" .. EXCLUDECHARS .. "$");
end)
if contains_words then
local function workaround_to_exclude_chars(s)
return mw.ustring.gsub(s, EXCLUDECHARS, "]]%1[[") end
local default_head = "]"
default_head = mw.ustring.gsub(default_head, "%%]", "") -- remove any empty links (which could have been created above at the beginning or end of the string)
data.heads = {default_head}
end
end
local label, altSc
if sc:getCode() == "Latn" then
label = "Cyrillic spelling"
altSc = m_sc.getByCode("Cyrl")
else
label = "Latin spelling"
altSc = m_sc.getByCode("Latn")
end
link_translit = function(head)
return m_links.full_link( {term = m_translit.tr(head, sc:getCode()),lang=lang, sc=altSc})
end
local translits = table.concat( map(link_translit, heads), " ''or'' ")
remove_ticks = function(head) return mw.ustring.gsub(head, '`', "") end
heads = map(remove_ticks, heads)
inflections = inflections or {}
table.insert(inflections, {label=label, translits})
return m_headword.full_headword(lang, sc, heads, {}, genders or {"?"}, inflections, categories or {}, sort_key, force_cat_output) .. (yat and sh_yat(yat) or "")
end
local params = {
= {},
-- PoS is the first argument here
= {required = true},
= {},
= {},
= {},
= {},
= {list = true, allow_holes = true, default = ""},
= {list = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true, type = "boolean"},
= {list = true, allow_holes = true},
}
--this is mostly a reworking of head_t from headword/templates
function export.head_t(frame)
local args = require("Module:parameters").process(frame:getParent().args, params)
-- Gather basic parameters
local sort_key = args
local pos = args
local cat2 = args
local cat3 = args
local cat4 = args
local heads = args
local genders = args
local yat = args
local accels = args
local requests = args
local alts = args
local gs = args
local ids = args
local langs = args
local nolinks = args
local quals = args
local scs = args
local trs = args
--assuming that all heads are in the same script
local sc = m_sc.findBestScript(heads,lang)
-- Gather inflected forms
local inflections = {}
--ignore obsolete script parameters
local start_from = 1
if args == 'r' or args == 'c' then start_from = 2 end
-- Go over all the inflection parameters
for i = start_from, math.ceil(args.maxindex / 2) do
local infl_part = {
label = args,
accel = accels,
request = requests,
}
local form = {
term = args,
alt = alts,
genders = {gs},
id = ids,
lang = lang,
nolink = nolinks,
qualifiers = {quals},
sc = sc
}
-- If no term or alt is given, then the label is shown alone.
if form.term or form.alt then
table.insert(infl_part, form)
end
if infl_part.label == "or" then
-- Append to the previous inflection part, if one exists
if #infl_part > 0 and inflections then
table.insert(inflections, form)
end
elseif infl_part.label then
-- Add a new inflection part
table.insert(inflections, infl_part)
end
end
-- Get/set categories
local categories = {}
local tracking_categories = {}
if pos then
table.insert(categories, lang_canon .. " " .. pos)
end
if cat2 then
table.insert(categories, lang_canon .. " " .. cat2)
end
if cat3 then
table.insert(categories, lang_canon .. " " .. cat3)
end
if cat4 then
table.insert(categories, lang_canon .. " " .. cat4)
end
if #categories == 0 and mw.title.getCurrentTitle().nsText == "Template" then
categories = {"Undetermined nouns"}
end
return
head (sc, heads, genders, inflections, categories, sort_key, force_cat_output, yat) ..
require("Module:utilities").format_categories(tracking_categories, lang, sort_key)
end
return export