local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char
-- pattern ()(?)(?)(?)
local tt = {
-- consonants
= "k", = "x", = "ng", = "ts", = "s", = "y",
= "t", = "th", = "l", = "p", = "ph", = "m",
= "f", = "w", = "h", = "’", = "kh", = "tsh", = "n",
-- vowels
= "aa", = "i", = "e", = "ae", = "u",
= "o", = "oa", = "ue", = "oe", = "aue",
= "y",
}
local tone_table = {
-- different ordering from Unicode: http://www.seasite.niu.edu/tai/TaiDehong/index.htm
-- also supports old orthography
= u(0x0308), = u(0x0308), = u(0x0308), -- 2 ä
= u(0x030C), = u(0x030C), = u(0x030C), -- 3 ǎ
= u(0x0300), = u(0x0300), = u(0x0300), = u(0x0300), -- 4 à
= u(0x0307), = u(0x0307), = u(0x0307), -- 5 ȧ
= u(0x0301), = u(0x0301), = u(0x0301), = u(0x0301), -- 1 á
= "", -- 6 a
}
local tone_key = "([ᥰ-ᥴ"
.. u(0x0308) .. u(0x00A8)
.. u(0x030C) .. u(0x02C7)
.. u(0x0300) .. u(0x0060) .. u(0x02CB)
.. u(0x0307) .. u(0x02D9)
.. u(0x0301) .. u(0x00B4) .. u(0x02CA) .. "]?)"
function export.tr(text, lang, sc, debug_mode)
if type(text) == "table" then -- called directly from a template
text = text.args
end
text = gsub(text, "()()", "%1a%2")
text = gsub(text, ".", tt)
-- adds tone diacritic
for old in mw.text.gsplit(text, " ") do
new = gsub(old, "()(*)" .. tone_key, function(v, x, t)
return v .. tone_table .. x
end)
text = gsub(text, old, new, 1)
end
return text
end
return export