local export = {}
local m_str_utils = require("Module:string utilities")
local decomp = mw.ustring.toNFD
local find = m_str_utils.find
local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local len = m_str_utils.len
local lower = m_str_utils.lower
local lang = require("Module:languages").getByCode("kri") -- Krio language object
local ipa = require("Module:IPA") -- IPA display module
local U = require("Module:string/char")
local acute = U(0x0301) -- acute accent
local grave = U(0x0300) -- grave accent
local circ = U(0x0302) -- circumflex accent
local C = "bcdfgɠhjkƙlmnŋɲpqrsʃtʧvwxyzʒBCDFGHJKLMNŊPQRSTVWXYZ" -- consonants
local V = "aeɛioɔuAEƐIOƆU" -- vowels
local T = acute .. grave .. circ -- tones
local syll = "‧" -- syllabification marker
local bound = "#" .. syll -- syllable boundary
-- Syllabify the term
local function syllablify(term, hide_borders)
-- Mark all word borders with #
term = gsub(term, "(+)", "#%1#")
-- Split the term into syllables
term = gsub(term, "(-)(??)", "%1" .. syll .. "%2")
-- Shift syllable marker for certain digraphs
term = gsub(term, "()" .. syll .. "()", syll .. "%1%2") -- ch/sh/zh
term = gsub(term, "()" .. syll .. "()", syll .. "%1%2") -- gb
term = gsub(term, "()" .. syll .. "()", syll .. "%1%2") -- kp
term = gsub(term, "()" .. syll .. "()", syll .. "%1%2") -- ny
-- Remove leading syllable boundaries at the beginning of words or explicitly marked syllables
term = gsub(term, "(%-?*)" .. syll, "%1")
-- Convert explicitly marked boundaries
term = gsub(term, "%.", syll)
-- Remove word borders if requested
return hide_borders and gsub(term, "#", "") or term
end
-- Get pronunciation from syllablified term
function export.toIPA(term)
-- Decompose entry
term = decomp(term)
-- Syllabify the term
term = syllablify(term, false)
-- Make it lowercase
term = lower(term)
-- Substitute digraphs
local digraphs = {
= "ʧ",
= "ɠ",
= "ƙ",
= "ɲ",
= "t",
= "ʃ",
= "ʒ",
}
term = gsub(term, "+", digraphs)
-- Perform respelling substitutions
term = gsub(term, "h(*)", "%1") -- syllable-final ⟨h⟩ is silent
term = gsub(term, "c()", "s%1") -- ⟨c⟩ before front vowels is pronounced /s/ before ⟨e⟩ and ⟨i⟩
term = gsub(term, "()i", "%1y") -- ⟨i⟩ after a vowel is treated as a consonant ⟨y⟩
term = gsub(term, "()u", "%1w") -- ⟨u⟩ after a vowel is treated as a consonant ⟨w⟩
-- Substitute single characters
local chars = {
= "k",
= "t͡ʃ",
= "ɡ͡b",
= "ɡ",
= "k͡p",
= "(h)", -- syllable-initial ⟨h⟩ is mostly silent
= "d͡ʒ",
= "k",
= "ʁ",
= "ks",
= "j",
}
term = gsub(term, "", chars)
-- Convert syllable boundaries to dots and remove word borders
return gsub(gsub(term, syll, "."), "#", "")
end
-- Main export function
function export.show(term)
-- get user input as table
if type(term) == "table" then
term = term.args
end
return export.toIPA(term)
end
return export