local export = {}
local u = mw.ustring.char
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local initial_table = {
= "k", = "kh", = "g", = "gh", = "ng",
= "ts", = "tsh", = "z", = "zh", = "ny",
= "tt", = "tth", = "dd", = "ddh", = "nn",
= "t", = "th", = "d", = "dh", = "n",
= "p", = "ph", = "f", = "b", = "bh", = "m",
= "y", = "r", = "l", = "w",
= "x", = "s", = "h", = "ll", = "’",
}
local glide_table = {
= "j",
= "r",
= "w",
= "",
}
local vowel_table = {
= "a",
= "aa",
= "i",
= "e",
= "ae",
= "u",
= "uu",
= "oa",
= "ue",
= "oe",
= "aa",
= "ii",
= "ee",
= "aae",
= "o",
= "oa",
= "ue",
= "oe",
= "ay",
= "aay",
= "aay",
= "uy",
= "oy",
= "oay",
= "uey",
= "oey",
= "aw",
= "aaw",
= "iw",
= "ew",
= "aew",
= "aue",
}
local coda_table = {
= "m",
= "n",
= "ng",
= "p",
= "t",
= "k",
= "",
}
local tone_table = {
= u(0x030C),
= u(0x0300),
= u(0x0304),
= u(0x0301),
= u(0x0302) .. u(0x0330),
= u(0x1DC8),
}
local digits = {
= "0", = "1", = "2", = "3", = "4",
= "5", = "6", = "7", = "8", = "9",
= "0", = "1", = "2", = "3", = "4",
= "5", = "6", = "7", = "8", = "9",
}
local syllable_pattern =
"^()" ..
"(?)" ..
"(*)" ..
"(?်?)" ..
"(?)$"
local repeat_syllabify =
"()()"
function export.tr(text, lang, sc)
text = gsub(text, ".", digits)
while match(text, repeat_syllabify) do
text = gsub(text, repeat_syllabify, "%1 %2")
end
for old in mw.text.gsplit(text, " ") do
new = gsub(old, syllable_pattern, function(initial, glide, vowel, coda, tone)
local untoned = initial_table ..
(vowel_table or
glide_table ..
(vowel_table or
(vowel_table or vowel) ..
(coda_table or coda)))
return gsub(untoned, "()", "%1" .. tone_table, 1)
end)
text = gsub(text, old, new, 1)
end
if not match(text, "") then
return text
else
return nil
end
end
return export