Pronunciation module for Hlai. See {{lic-pron}}
.
local export = {}
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local match = mw.ustring.match
local lang = require("Module:languages").getByCode("lic")
local convert_initial = {
= "p", = "pʰ", = "pl", = "ɓ",
= "m", = "ˀw", = "f", = "v",
= "t", = "tʰ", = "ɗ",
= "t͡s", = "t͡s", = "t͡sʰ", = "t͡sʰ",
= "n", = "r", = "l", = "ɬ", = "z",
= "ɲ", = "ˀj",
= "k", = "kʰ", = "ɡ", = "ŋ",
= "kʷ", = "kʷʰ", = "ɡʷ", = "ŋʷ",
= "h", = "hʲ", = "hʷ",
= "ʔ",
}
local convert_final = {
= "a",
= "aːi", = "aːu",
= "aːm", = "aːn", = "aːɲ", = "aːŋ",
= "aːp", = "aːt", = "aːc", = "aːk",
= "ai", = "au", = "aɯ",
= "am", = "an", = "aɲ", = "aŋ",
= "aːp", = "at", = "ac", = "ak",
= "eː",
= "eːu",
= "eːm", = "eːn", = "eːŋ",
= "eːp", = "eːt", = "eːk",
= "ei", = "eɯ",
= "em", = "en", = "eɲ", = "eŋ",
= "ep", = "et", = "ec", = "ek",
= "i",
= "iːu",
= "iːm", = "iːn", = "iːŋ",
= "iːp", = "iːt", = "iːk",
= "ia", = "iu",
= "im", = "in", = "iŋ",
= "ip", = "it", = "ik",
= "oː",
= "oːi",
= "oːm", = "oːn", = "oːŋ",
= "oːp", = "oːt", = "oːc", = "oːk",
= "ou",
= "om", = "oŋ",
= "op", = "ok",
= "u",
= "uːi",
= "uːn", = "uːɲ", = "uːŋ",
= "uːt", = "uːc", = "uːk",
= "ua", = "ui",
= "un", = "uɲ",
= "ut", = "uc",
= "ɯ",
= "ɯːi",
= "ɯːm", = "ɯːn", = "ɯːŋ",
= "ɯːp", = "ɯːt", = "ɯːk",
= "ɯa",
= "ɯm", = "ɯn", = "ɯŋ",
= "ɯp", = "ɯt", = "ɯk",
}
local function get_tone(syllable)
if find(syllable, "x$") then
return "˥", gsub(syllable, "x$", "")
elseif find(syllable, "s$") then
return "˩", gsub(syllable, "s$", "")
elseif find(syllable, "y?$") then
local coda = match(syllable, "(y?)$")
if find(gsub(syllable, coda .. "$", ""), "y?$") then
return "˥˧", gsub(syllable, coda .. "$", "")
end
return "˥", syllable
else
return "˥˧", syllable
end
end
local function syllabify(text)
text = gsub(text, "'", ".")
text = gsub(text, "()()", "%1.%2")
text = gsub(text, "()()", "%1.%2")
text = gsub(text, "()()", "%1.%2")
text = gsub(text, "(pp)(?w?)", "%1.%2")
text = gsub(text, "(tt)(?w?)", "%1.%2")
text = gsub(text, "(kk)(?w?)", "%1.%2")
text = gsub(text, "(?)(?w?)", "%1.%2")
return mw.text.gsplit(text, "%.")
end
function export.ipa(text)
text = string.lower(text)
local syllables = {}
for syllable in syllabify(text) do
if match(syllable, "^g?uu$") then
syllable = syllable .. "s"
elseif syllable == "zuu" then
syllable = syllable .. "x"
end
local initial, final, tone_value
tone_value, syllable = get_tone(syllable)
initial, final = match(syllable, "^(??w?)(+)$")
if not initial or not final then
error(syllable .. "cannot be recognized")
end
local initial_ipa, final_ipa = convert_initial, convert_final
if not initial_ipa then
error(initial .. " is not a valid initial")
elseif not final_ipa then
error(final .. " is not a valid final")
end
table.insert(syllables, initial_ipa..final_ipa..tone_value)
end
return "/" .. table.concat(syllables, ".") .. "/"
end
function export.show(frame)
local params = {
= { },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local text = args
if not text then text = mw.title.getCurrentTitle().text end
local display = ("* %s %s"):format(
require("Module:accent qualifier").format_qualifiers(lang, {"Standard Hlai", "]"}),
require("Module:IPA").format_IPA_full { lang = lang, items = {{ pron = export.ipa(text) }} }
)
return display
end
return export