local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
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_tr = require('Module:xchc-translit')
local m_ipa = require('Module:xchc-pron')
local lang = require('Module:languages').getByCode("xchc")
local PAGENAME = mw.title.getCurrentTitle().text
local NAMESPACE = mw.title.getCurrentTitle().nsText
local export = {}
local voiced = "mnɲŋbdɡvzʒɣlr"
local voiceless = "ptkfsʃxh"
local consonant = "[" .. voiced .. voiceless .. "]"
local vowel = "[aeɛioɔuyø]"
local genders = {["a"] = "animate", ["i"] = "inanimate"}
local function wordpron(w)
return m_ipa.crux(w)
end
local function gsubbh(word, data, def)
local ipa = wordpron(word)
local backh = ipa:match("ɛ") and "ɛ" or ipa:match("ɔ") and "ɔ" or nil
local repl = {["ɛ"] = data.e, ["ɔ"] = data.o, ["e"] = data.e, ["o"] = data.o}
return word:gsub("B", repl[backh or def])
end
local function gsubrh(word, data, def)
local ipa = wordpron(word)
local roundh = ipa:match("[yuɔo]") and "r" or ipa:match("[ie]") and "u" or nil
local repl = {["r"] = data.r, ["u"] = data.u}
return word:gsub("R", repl[roundh or def])
end
function export.show(frame)
local parent_args = frame:getParent().args
local g = NAMESPACE == "Template" and "a" or parent_args[1]
local word = NAMESPACE == "Template" and "өра̄" or parent_args["word"] or PAGENAME
local unc = parent_args["unc"] or false
local args = {}
if g ~= "i" and g ~= "a" then error("Unknown gender: it must be either ‘i’ or ‘a’") end
local data = {}
data.word = word
data.g = g
data.sg = ""
data.pau = wordpron(word):match("[eiøy]$") and "ч"
or wordpron(word):match("[ɛa]$") and "н"
or wordpron(word):match("[uoɔ]$") and "ӈ"
or gsubbh("Bӈ",{["o"]="о̆",["e"]="э̆"},"ɔ")
data.pl = {
["i"] = wordpron(word):match(voiceless .. "ː?$") and gsubbh("фBд",{["o"]="ө",["e"]="э"},"ɛ") or gsubbh("вBд",{["o"]="ө",["e"]="э"},"ɛ"),
["a"] = wordpron(word):match(voiceless .. "ː?$") and gsubbh("шBд",{["o"]="о̆",["e"]="э̆"},"ɔ") or gsubbh("жBд",{["o"]="о̆",["e"]="э̆"},"ɔ")
}
return make_table(data)
end
function make_table(data)
local function show_form(form)
local function link(term)
local links = {}
for alt in gmatch(term, "([^%s,]+)") do
alt = term == "—" and term or "[[Contionary:" .. alt .. "|" .. alt .. "]]"
table.insert(links, alt)
end
return table.concat(links, ", ")
end
if not form then
return "—"
end
local ret, tr_ret = {}, {}
for _, subform in ipairs(type(form) == "table" or {form}) do
table.insert(ret, link(subform))
local tr_subform, _ = m_tr.tr(subform,lang)
table.insert(tr_ret, tr_subform)
end
return table.concat(ret, ", ") .. '<br/><span style="color: #888;">' .. table.concat(tr_ret, ", ") .. "</span>"
end
function make_cases(data)
local cases = {"nominative", "accusative", "dative", "genitive", "instrumental", "prosecutive", "adessive<br/>comitative", "ablative<br/>elative", "illative<br/>allative"}
local numbers = {"singular", "paucal", "plural"}
local ret = {}
if data.unc then
numbers[2], numbers[3], numbers_sh[2], numbers_sh[3] = nil, nil, nil, nil
end
table.insert(ret, '! style="width:8em;" |\n')
for _, number in ipairs(numbers) do
table.insert(ret, "! " .. number .. "\n")
end
table.insert(ret, "|-\n")
for _, case in ipairs(cases) do
local c_sh = case:sub(1,3)
table.insert(ret, '! style="background:#DEE9FB" |' .. case .. '\n')
for _, number in ipairs(numbers) do
local n_sh = number:sub(1,2)
local w_number = {["si"] = data.word .. data.sg, ["pa"] = data.word .. data.pau, ["pl"] = data.word .. data.pl[data.g]}
local decl = {
["nom"] = "",
["acc"] = w_number[n_sh]:match(vowel .. "ː?$") and "дза" or w_number[n_sh]:match(voiced .. "ː?$") and "да" or "та",
["dat"] = w_number[n_sh]:match(vowel .. "ː?$") and "ша" or w_number[n_sh]:match(voiced .. "ː?$") and "за" or "са",
["gen"] = "ля",
["ins"] = w_number[n_sh]:match(vowel .. "ː?$") and "лза" or gsubbh("Bлз",{["o"]="ө",["e"]="э"},"ɔ"),
["pro"] = gsubbh("сBц",{["o"]="ө",["e"]="э"}, "ɔ"),
["ade"] = "ляц",
["abl"] = gsubrh("сR",{["r"]="u",["u"]="i"},"r") .. gsubbh("шB",{["o"]="о̄̆",["e"]="э̄̆"},"ɛ"),
["ill"] = gsubrh("кRб",{["r"]="ү",["u"]="ы"},"u"),
}
table.insert(ret, "| " .. show_form(w_number[n_sh] .. decl[c_sh]) .. "\n")
end
table.insert(ret, "|-\n")
end
return table.concat(ret)
end
local t = [=[
<div class="mw-collapsible mw-collapsed" style="margin: 0px 0px -1px 0px; padding: 2px; border: 1px solid #aaaaaa; text-align: center; border-collapse: collapse; font-size: 95%; overflow: auto; width: auto; min-width: 35em; display:inline-block; color: #202122;">
<div style="min-height: 1.6em; font-weight: bold; font-size: 100%; text-align: left; padding-left: 10px; background-image: -webkit-gradient(linear,left top,left bottom,from(#EFEFEF),to(#DFDFDF),color-stop(0.6,#E3E3E3)); background-image: -moz-linear-gradient(top,#EFEFEF,#E3E3E3 60%,#DFDFDF); background-image: -o-linear-gradient(top,#EFEFEF,#E3E3E3 60%,#DFDFDF); background: #DEE9FB; cursor: pointer;">'''Declension of ''{title}''''' (<span style="font-weight:normal; font-size: smaller;">{after_title}</span>) </div>
<div class="mw-collapsible-content" style="font-size: 100%; display: block;">
{\op}|style="background:#F9F9F9; text-align:center; min-width:35em; width:100%;" class="inflection-table"
|- style="background:#93B7F1"
{all_cases}
|-
|{\cl}</div></div>
]=]
return require("Module:string utilities").format(t,{
title=data.word,
after_title="[[:Category:Chiingimec " .. genders[data.g] .. " nouns|" .. genders[data.g] .. "]]",
all_cases=make_cases(data)}
)
end
return export