local lang = require("Module:languages").getByCode("cy")
local export = {}
local rfind = mw.ustring.find
local usub = mw.ustring.sub
local ulower = mw.ustring.lower
local PAGENAME = mw.title.getCurrentTitle().text
local IRREGMARKER = "<sup>△</sup>"
local mutation_rules = {
['b'] = {"f", "m",},
['c'] = {"g", "ngh", "ch",},
['ch'] = {},
['d'] = {"dd", "n",},
['f'] = {},
['g'] = {"", "ng"},
['h'] = {},
['l'] = {},
['ll'] = {"l",},
['m'] = {"f",},
['n'] = {},
['p'] = {"b", "mh", "ph",},
['r'] = {},
['rh'] = {"r",},
['s'] = {},
['t'] = {"d", "nh", "th",},
}
function export.get_mutation_data(term)
local data = {}
data.radical = term
data.initial = usub(term, 1, 1)
data.is_uppercase = ulower(data.initial) ~= data.initial
data.initial = ulower(data.initial)
data.final = usub(term, 2, -1)
data.first_two = data.initial .. usub(data.final, 1, 1)
if data.first_two == 'll' or data.first_two == 'rh' or data.first_two == 'ch' then
data.initial = data.first_two
data.final = usub(data.final, 2, -1)
end
data.vowel = false
data.mut1 = nil
data.mut2 = nil
data.mut3 = nil
if rfind(data.initial, "[aâàeêèiîìoôòuûùwŵẁyŷỳ]") then
data.vowel = true
data.mut3 = "h" .. data.initial
elseif mutation_rules[data.initial] then
data.mut1 = mutation_rules[data.initial][1]
data.mut2 = mutation_rules[data.initial][2]
data.mut3 = mutation_rules[data.initial][3]
else
error("no mutation rule found for this term: " .. term)
end
return data
end
function export.show(frame)
args = frame:getParent().args
radical = args[1] or PAGENAME
initial = mw.ustring.sub(radical,1,1)
is_uppercase = mw.ustring.lower(initial) ~= initial
initial = mw.ustring.lower(initial)
final = mw.ustring.sub(radical,2,-1)
first_two = initial .. mw.ustring.sub(final,1,1)
if first_two=='ll' or first_two=='rh' or first_two=='ch' then
initial = first_two
final = mw.ustring.sub(final,2,-1)
end
vowel = false
local mut1 = nil
local mut2 = nil
local mut3 = nil
if mw.ustring.match(initial,'[aâeêiîoôuûwŵyŷ]') then
vowel = true
mut3 = "h" .. initial
elseif mutation_rules[initial] then
mut1 = mutation_rules[initial][1]
mut2 = mutation_rules[initial][2]
mut3 = mutation_rules[initial][3]
else
error('rule not specified for this word:'..radical)
end
local function link(target, accel)
target = target .. final
if is_uppercase then
target = mw.ustring.upper(mw.ustring.sub(target,1,1)) .. mw.ustring.sub(target,2,-1)
end
return require("Module:links").full_link({lang = lang, accel = {form = accel, lemma = radical}, term = target})
end
mut1 = mut1 and link(mut1, 'soft')
mut2 = mut2 and link(mut2, 'nasal')
mut3 = mut3 and link(mut3, vowel and 'h-prothesis' or 'aspirate')
radical = radical == PAGENAME and "'''"..radical.."'''" or '[['..radical..'#威爾士語|'..radical..']]'
result = '{| border="1" cellpadding="4" cellspacing="0" class="inflection-table" style="align: left; margin: 0.5em 0 0 0; border-style: solid; border: 1px solid #7f7f7f; border-right-width: 2px; border-bottom-width: 2px; border-collapse: collapse; background-color: #F8F8F8; font-size: 95%;"'
result = result .. '\n|-'
result = result .. '\n! colspan=4 | [[Appendix:威爾士語輔音變化|輔音變化]]'
result = result .. '\n|-'
result = result .. '\n! 原型 !! 濁化 !! 鼻音化 !! ' .. (vowel and 'h-音化' or '清音化')
result = result .. '\n|-'
result = result .. '\n| ' .. radical
result = result .. '\n| ' .. (mut1 or "無變化")
result = result .. '\n| ' .. (mut2 or "無變化")
result = result .. '\n| ' .. (mut3 or "無變化")
result = result .. '\n|-'
result = result .. "\n| colspan=4 | <small style=\"font-size:85%;\">注意:有些形式僅是推測,不是每種形式都一定存在。</small>"
result = result .. '\n|}'
return result
end
return export