Rakhine (Arakanese) pronunciation and romanisation module. See {{rki-IPA}}
.
See Module:rki-pron/testcases.
local export = {}
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local match = mw.ustring.match
local system_list = {
{ 1, = "phonetic", = "IPA" },
{ 2, = "orthographic", = "MLCTS" },
{ 3, = "orthographic", = "ALA-LC" },
}
local initial_table = {
= { "k", "k", "k" },
= { "t͡ɕ", "ky", "ky" },
= { "kɹ", "kr", "kr" },
= { "t͡ɕw", "kyw", "kyv" },
= { "kɹw", "krw", "krv" },
= { "kw", "kw", "kv" },
= { "kʰ", "hk", "kh" },
= { "t͡ɕʰ", "hky", "khy" },
= { "ʃ", "hkr", "khr" },
= { "t͡ɕʰ", "hkr", "khr" },
= { "ʃ", "hkr", "khr" },
= { "t͡ɕʰw", "hkyw", "khyv" },
= { "kʰɹw", "hkrw", "khrv" },
= { "kʰw", "hkw", "khv" },
= { "ɡ", "g", "g" },
= { "d͡ʑ", "gy", "gy" },
= { "gɹ", "gr", "gr" },
= { "d͡ʑw", "gyw", "gyv" },
= { "ɡw", "gw", "gv" },
= { "ɡ", "gh", "gh" },
= { "ŋ", "ng", "ṅ" },
= { "ŋ̊", "hng", "ṅh" },
= { "ɲ", "ngr", "ṅr" },
= { "ɲ̊", "hngr", "ṅrh" },
= { "ŋw", "ngw", "ṅv" },
= { "ŋ̊w", "hngw", "ṅvh" },
= { "s", "c", "c" },
= { "sw", "cw", "cv" },
= { "sʰ", "hc", "ch" },
= { "sʰw", "hcw", "chv" },
= { "z", "j", "j" },
= { "zw", "jw", "jv" },
= { "z", "jh", "jh" },
= { "ɲ", "ny", "ñ" },
= { "ɲ", "ny", "ññ" },
= { "ɲ̊", "hny", "ñh" },
= { "ɲ̊", "hny", "ññh" },
= { "ɲw", "nyw", "ñv" },
= { "ɲ̊w", "hnyw", "ñvh" },
= { "t", "t", "ṭ" },
= { "tʰ", "ht", "ṭh" },
= { "d", "d", "ḍ" },
= { "d", "dh", "ḍh" },
= { "n", "n", "ṇ" },
= { "n̥", "hn", "ṇh" },
= { "t", "t", "t" },
= { "tj", "ty", "ty" },
= { "tɹ", "tr", "tr" },
= { "tw", "tw", "tv" },
= { "tʰ", "ht", "th" },
= { "tʰw", "htw", "thv" },
= { "d", "d", "d" },
= { "dj", "dy", "dy" },
= { "dɹ", "dr", "dr" },
= { "dw", "dw", "dv" },
= { "d", "dh", "dh" },
= { "n", "n", "n" },
= { "n̥", "hn", "nh" },
= { "nj", "ny", "ny" },
= { "nw", "nw", "nv" },
= { "n̥w", "hnw", "nvh" },
= { "p", "p", "p" },
= { "pj", "py", "py" },
= { "pɹ", "pr", "pr" },
= { "pw", "prw", "prv" },
= { "pw", "pw", "pv" },
= { "pʰ", "hp", "ph" },
= { "pʰj", "hpy", "phy" },
= { "pʰɹ", "hpr", "phr" },
= { "pʰw", "hpw", "phv" },
= { "b", "b", "b" },
= { "bj", "by", "by" },
= { "bɹ", "br", "br" },
= { "bw", "bw", "bv" },
= { "b", "bh", "bh" },
= { "pʰ", "bh", "bh" },
= { "bw", "bhw", "bhv" },
= { "pʰw", "bhw", "bhw" },
= { "m", "m", "m" },
= { "m̥", "hm", "mh" },
= { "mj", "my", "my" },
= { "m̥j", "hmy", "myh" },
= { "mɹ", "mr", "mr" },
= { "m̥ɹ", "hmr", "mrh" },
= { "mɹw", "mrw", "mrv" },
= { "m̥w", "hmrw", "mrvh" },
= { "mw", "mw", "mv" },
= { "m̥w", "hmw", "mvh" },
= { "j", "y", "y" },
= { "ʃ", "hy", "yh" },
= { "ʃ", "hsy", "syh" },
= { "jw", "yw", "yv" },
= { "ɹ", "r", "r" },
= { "hɹ", "hr", "rh" },
= { "ʃ", "hr", "rh" },
= { "ɹw", "rw", "rv" },
= { "hɹw", "hrw", "rvh" },
= { "l", "l", "l" },
= { "l̥", "hl", "lh" },
= { "j", "ly", "ly" },
= { "j", "hsy", "syh" },
= { "lj", "ly", "ly" },
= { "ʃ", "hly", "lyh" },
= { "l̥j", "hly", "lyh" },
= { "lw", "lw", "lv" },
= { "l̥w", "hlw", "lvh" },
= { "w", "w", "v" },
= { "ʍ", "hw", "vh" },
= { "θ", "s", "s" },
= { "ð", "s", "s" },
= { "θw", "sw", "sv" },
= { "ðw", "sw", "sw" },
= { "h", "h", "h" },
= { "hw", "hw", "hv" },
= { "l", "l", "ḷ" },
= { "ʔ", "", "ʼ" },
-- only appears after a vowel in the same word
= { "ʔθ", "ss", "ss" },
= { "ʔ", "", "" },
= { "", "", "" },
= { nil, "y", "y" },
= { nil, "r", "r" },
= { nil, "w", "w" },
}
local initial_voicing = {
= "ဂ",
= "ဂ",
= "ဇ",
= "ဇ",
= "ဍ",
= "ဍ",
= "ဒ",
= "ဒ",
= "ဗ",
= "ဗ",
= "ဖ",
}
local final_table = {
= { "a̰", "a.", "a" },
= { "ɔʔ", "ak", "akʻ" },
= { "ɔ̀ɴ", "ang", "aṅʻ" },
= { "aɪʔ", "ac", "acʻ" },
= { "è", "any", "aññʻ" },
= { "ì", "any", "aññʻ" },
= { "ɛ̀", "any", "aññʻ" },
= { "aɪ̀ɴ", "any", "añʻ" },
= { "ɛʔ", "at", "atʻ" },
= { "ɛ̀ɴ", "an", "anʻ" },
= { "ɛʔ", "ap", "apʻ" },
= { "ɛ̀ɴ", "am", "amʻ" },
= { "è", "ai", "ayʻ" },
= { "ɛ̀ɴ", "am", "aṃ" },
= { "à", "a", "ā" },
= { "à", "a", "ā" },
= { "ḭ", "i.", "i" },
= { "eɪʔ", "it", "itʻ" },
= { "èɪɴ", "in", "inʻ" },
= { "eɪʔ", "ip", "ipʻ" },
= { "èɪɴ", "im", "imʻ" },
= { "èɪɴ", "im", "iṃ" },
= { "ì", "i", "ī" },
= { "ṵ", "u.", "u" },
= { "oʊʔ", "ut", "utʻ" },
= { "òʊɴ", "un", "unʻ" },
= { "oʊʔ", "up", "upʻ" },
= { "òʊɴ", "um", "umʻ" },
= { "òʊɴ", "um", "uṃ" },
= { "ù", "u", "ū" },
= { "ì", "e", "e" },
= { "è", "e", "e" },
= { "é", "ai:", "ai" },
= { "ɔ́", "au:", "o" },
= { "aʊʔ", "auk", "okʻ" },
= { "àʊɴ", "aung", "oṅʻ" },
= { "ɔ̀", "au", "oʻ" },
= { "ò", "ui", "ui" },
= { "aɪʔ", "uik", "uikʻ" },
= { "àɪɴ", "uing", "uiṅʻ" },
= { "wɛʔ", "wat", "vatʻ" },
= { "wɛ̀ɴ", "wan", "vanʻ" },
= { "wɛ̀ʔ", "wap", "vapʻ" },
= { "wɛ̀ɴ", "wam", "vamʻ" },
= { "wɛ̀ɴ", "wam", "vaṃ" },
= { "ə", "a", "a" },
= { "", "", "ʻ" },
}
local nucleus_table = {
= { "à", "a", "a" },
= { "ì", "i", "i" },
= { "ù", "u", "u" },
= { "ɔ̀", "au", "o" },
= { "ɔ̀", "au", "o" },
= { "ʊ̀", "wa", "va" },
}
local indep_letter_table = {
= { "ḭ", "i.", "i" },
= { "ì", "i", "ī" },
= { "ṵ", "u.", "u" },
= { "ù", "u", "ū" },
= { "ì", "e", "e" },
= { "ḭ", "e", "e*" },
= { "ɔ́", "au:", "o" },
= { "ɔ̀", "au", "oʻ" },
= { "n̥aɪʔ", "hnai.", "n*" },
= { "ɹwḭ", "rwe", "r*" },
}
local tone_table = {
= { "́", ":", "ʺ" },
= { "̰", ".", "ʹ" },
}
local ambig_intersyl = {
= {
},
= {
= 1, = 1, = 1,
= 1, = 1, = 1,
= 1, = 1,
= 1, = 1, = 1,
= 1, = 1, = 1,
= 1, = 1, = 1,
},
= {
},
= {
= 1, = 1, = 1,
= 1, = 1, = 1,
= 1, = 1,
= 1, = 1, = 1,
= 1, = 1,
= 1, = 1, = 1,
= 1, = 1, = 1,
},
= {
= 1,
},
}
local reverse_table = {
= "မှ", = "မ",
= "နှ", = "န",
= "ညှ", = "ည",
= "ငှ", = "င",
= "ပ", = "ဖ", = "ဗ",
= "တ", = "ထ", = "ဒ",
= "ကျ", = "ချ", = "ဂျ",
= "က", = "ခ", = "ဂ",
= "အ",
= "သ", = "+သ",
= "စ", = "ဆ", = "ဇ",
= "ရှ",
= "ဟ",
= "ရ",
= "ယ",
= "ဝှ", = "ဝ",
= "လှ", = "လ",
= "မွှ", = "မွ", = "မျှ", = "မျ",
= "နွှ", = "နွ",
= "ညွှ", = "ညွ",
= "ငွှ", = "ငွ",
= "ပွ", = "ဖွ", = "ဗွ",
= "ပျ", = "ဖျ", = "ဗျ",
= "တွ", = "ထွ", = "ဒွ",
= "ကျွ", = "ချွ", = "ဂျွ",
= "ကွ", = "ခွ", = "ဂွ",
= "သွ",
= "စွ", = "ဆွ", = "ဇွ",
= "ရွှ",
= "ဟွ",
= "ယွ",
= "လွှ", = "လွ", = "*လျှ", = "*လျ",
= "ီ", = "ီး", = "ိ", = "စ်",
= "င်", = "င်း", = "င့်",
= "ေ", = "ေး", = "ေ့", = "ိတ်",
= "ိန်", = "ိန်း", = "ိန့်",
= "ယ်", = "ဲ", = "ယ့်", = "က်",
= "ိုင်", = "ိုင်း", = "ိုင့်",
= "ိုက်",
= "ာ", = "ား", = "", = "တ်",
= "န်", = "န်း", = "န့်",
= "ော်", = "ော", = "ော့", = "ောက်",
= "ောင်", = "ောင်း", = "ောင့်",
= "ို", = "ိုး", = "ို့", = "ုပ်",
= "ုန်", = "ုန်း", = "ုန့်",
= "ူ", = "ူး", = "ု", = "ွတ်",
= "ွန်", = "ွန်း", = "ွန့်",
= "'",
}
local repl_string = "(**)(?)"
function syllabify(text)
text = gsub(text, "('?)(*)", function(a, b)
if a .. b ~= "" then return a .. " " .. b end
end)
text = gsub(text, "(?)(.?)(.?)", function(a, b, c)
return (c == "္" and " "..a..b.." "..c or (c == "်" and " "..a..b..c or " "..a.." "..b..c))
end) .. " "
text = gsub(text, "(်း?'?)", "%1 ")
text = gsub(text, "()(်)", "%2%1")
while match(text, repl_string) do
text = gsub(text, repl_string, "%1 %2")
end
text = gsub(text, "္", " , ")
text = gsub(text, " +", " ")
text = gsub(text, "^ ?(.*) ?$", "%1")
text = gsub(text, " , ", " ")
text = gsub(text, " ()", "%1")
return text
end
function initial_by_char(initial_string, system_index, ref_table)
local initial_set = {}
for character in mw.text.gsplit(initial_string, "") do
local temp_initial = ref_table or error("Initial data not found.")
table.insert(initial_set, temp_initial or temp_initial)
end
return table.concat(initial_set)
end
function generate_respelling(text)
text = gsub(text, " ", " ")
text = gsub(text, "ါ", "ာ")
if match(text, "") then return text end
text = gsub(text, "(%+?)(*)(/?)(+)", function(voicing_mark, latin_initial, opt_sep, latin_final)
return
voicing_mark ..
(reverse_table or initial_by_char(latin_initial, nil, reverse_table)) ..
opt_sep ..
reverse_table
end)
return text
end
function process(initial, final, tone, schwa, system, system_index)
if match(initial .. final, "ွှ?") and system == "phonetic" then
initial = gsub(initial, "", "")
final = "ွ" .. final
else
initial = gsub(initial, "/", "")
end
initial_new = system == "phonetic" and gsub(initial, "%+.", initial_voicing) or initial
if indep_letter_table then
initial_new = match(initial_new, "") and "-" or ""
final = initial .. final
end
if initial_new == "မြွ" then require('Module:debug').track('rki-pron/mrw') end
initial_data =
initial_table
or initial_table", "")]
or (system == "orthographic"
and initial_by_char(initial_new, system_index, initial_table)
or error("Initial data not found."))
initial_value = initial_data or initial_data
if match(initial, "^%+") and system_index == 5 then
initial_value = initial_table
initial_value = gsub(initial_value, "^(+)", "<u>%1</u>")
end
final_data =
final_table .. schwa == "phonetic'" and schwa or final]
or (system == "phonetic"
and (final_table or indep_letter_table)
or indep_letter_table)
or gsub(final, "^(*)()(်?)$", function(first, second, third)
first_data = nucleus_table or final_table or indep_letter_table or first
second_data = initial_table or second
first = first_data ~= first and first_data or first
second = second_data ~= second
and second_data .. ((system_index == 3 and third ~= "") and "ʻ" or "")
or second
return (gsub(first .. second, "()(.*)", "%2"))
end)
final_value = type(final_data) == "table" and final_data or final_data
final_value = mw.ustring.toNFD(final_value)
if tone == "" then
tone_value = ""
else
if system_index ~= 4 then final_value = gsub(final_value, "̀", "") end
final_value = gsub(final_value, "", "")
if system .. schwa == "phonetic'" then
tone_value = ""
else
tone_data = tone_table or error("Tone data not found.")
tone_value = tone_data
end
end
if system_index == 1 then
final_value = gsub(final_value, "^()", "%1" .. tone_value)
elseif system_index == 5 then
final_value = gsub(final_value, "()(*)$", "%1" .. tone_value .. "%2")
else
final_value = final_value .. tone_value
end
return mw.ustring.toNFC(initial_value .. final_value)
end
function remove_wide_space(text)
return (gsub(text, " ", ""))
end
function concatenate(set, system_index)
if system_index == 1 then return remove_wide_space(table.concat(set)) end
result_text = remove_wide_space(table.concat(set, " "))
for count = 1, 3 do
result_text = gsub(result_text, "(.) (.)(?)",
function(previous, next, after_next)
if ambig_intersyl
or ((system_index == 2 or system_index == 4)
and (match(previous .. " " .. next, " ")
or (match(previous .. next .. after_next, "") and not match(after_next, "")))) then
return previous .. "-" .. next .. after_next
else
return previous .. next .. after_next
end
end)
end
return result_text
end
function export.get_romanisation(word, pronunciations, system, system_index, mode)
local sentences = {}
word = gsub(word, " ", "|")
if system == "phonetic" then
word = gsub(word, "ဿ", "တ်သ")
end
word = syllabify(word)
word = gsub(word, "ါ", "ာ")
if system == "phonetic" then
word = gsub(word, "ဝ()", "ဝွ%1")
end
for phrase in mw.text.gsplit(word, "|", true) do
local temp = {}
local syllable = mw.text.split(phrase, " ", true)
for syllable_index = 1, #syllable do
syllable = gsub(syllable, "()(်)", "%2%1")
temp = gsub(
syllable,
"^(*?ွ?ှ?/?)(*)(?)('?)$",
function(initial, final, tone, schwa)
return process(initial, final, tone, schwa, system, system_index)
end)
end
table.insert(sentences, concatenate(temp, system_index))
end
if mode == "translit_module" then return table.concat(sentences, " ") end
table.insert(pronunciations, table.concat(sentences, " "))
return pronunciations
end
function respelling_format(phonetic, page_title)
local page_title_set = mw.text.split(syllabify(page_title), " ")
local new_respellings = {}
for _, respelling in ipairs(phonetic) do
local respelling_set = mw.text.split(syllabify(respelling), " ")
if gsub(table.concat(respelling_set), "", "") == (gsub(table.concat(page_title_set), "ါ", "ာ")) then
for index, element in ipairs(respelling_set) do
if element ~= page_title_set then
respelling_set = '<span style="font-size:110%; color:#A32214; font-weight: bold">' .. element .. '</span>'
end
end
end
table.insert(new_respellings, table.concat(respelling_set))
end
text = table.concat(new_respellings, ", ")
text = remove_wide_space(text)
text = gsub(text, ".", initial_voicing)
text = gsub(text, "(ေ?)ာ", "%1ါ")
return text
end
function export.generate_tests(word, respelling)
respelling, word = generate_respelling(respelling), generate_respelling(word)
local pronunciations = {
= {},
= {},
= {},
= {},
= {},
}
local p, result = { = word, = respelling or word }, {}
table.sort(system_list, function(first, second) return first < second end)
for system_index, system in ipairs(system_list) do
pronunciations = export.get_romanisation(p], pronunciations, system, system_index)
end
for system_index = 1, 5 do
table.insert(result, table.concat(pronunciations))
end
return (gsub(gsub(table.concat(result, " | "), "<u>", "("), "</u>", ")"))
end
function export.make(frame)
local args = frame:getParent().args
local page_title = mw.title.getCurrentTitle().text
local title = generate_respelling(args or page_title)
local p, result = { = { title }, = {} }, {}
local pronunciations = {
= {},
= {},
= {},
= {},
= {},
}
if not args then args = { title } end
for index, item in ipairs(args) do
table.insert(p, (item ~= "") and generate_respelling(item) or nil)
end
table.sort(system_list, function(first, second) return first < second end)
for system_index, system in ipairs(system_list) do
for _, word in ipairs(p]) do
pronunciations = export.get_romanisation(word, pronunciations, system, system_index)
end
end
if title ~= table.concat(args) then
table.insert(result,
"* Phonetic respelling" .. (#p > 1 and "s" or "") .. ": " ..
tostring( mw.html.create( "span" )
:attr( "lang", "rki" )
:attr( "class", "Mymr" )
:wikitext( respelling_format( p, page_title ))) .. "\n" )
end
table.insert(result,
'* ]' ..
'<sup>(])</sup>: ' ..
(tostring( mw.html.create( "span" )
:attr( "class", "IPA" )
:wikitext( "/" .. gsub(table.concat(pronunciations, "/, /"), "ʔʔ", "ʔ.ʔ") .. "/" ))) ..
'\n* ] ')
for system_index = 2, 5 do
table.insert(result,
(system_index ~= 2 and " • " or "") ..
"''" .. system_list .. ":'' " ..
table.concat(pronunciations, "/"))
end
return table.concat(result)
end
return export