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" },
{ 4, = "phonetic", = "BGN/PCGN" },
{ 5, = "phonetic", = "Okell" },
}
local initial_table = {
= { "k", "k", "k", "k", "k" },
= { "kʰ", "hk", "kh", "hk", "hk" },
= { "kʰ", "hk", "kh", "hk", "hk" },
= { "khac", "khac", "khac", "khac", "khac" },
= { "kɛk", "kɛk", "kɛk", "kɛk", "kɛk" },
= { "kac", "kac", "kac", "kac", "kac" },
= { "koc", "koc", "koc", "koc", "koc" },
= { "kɤk", "kɤk", "kɤk", "kɤk", "kɤk" },
= { "kɔc", "kɔc", "kɔc", "kɔc", "kɔc" },
= { "kòk", "kòk", "kòk", "kòk", "kòk" },
= { "kɔk", "kɔk", "kɛ̀k", "kɛ̀k", "kɛ̀k" },
= { "kɔˀ", "kɔˀ", "kɔˀ", "kɔˀ", "kɔˀ" },
= { "keˀ", "keˀ", "keˀ", "keˀ", "keˀ" },
= { "kɒˀ", "kɒˀ", "kɒˀ", "kɒˀ", "kɒˀ" },
= { "kɜˀ", "kɜˀ", "kɜˀ", "kɜˀ", "kɜˀ" },
}
local final_table = {
= { "a̰", "a.", "a", "a.", "á" },
= { "ɛk", "ɛk", "ɛk‘", "ɛk", "ɛk" },
}
local nucleus_table = {
= { "à", "a", "a", "a", "a" },
= { "ò", "ò", "ò", "ò", "ò" },
}
local indep_letter_table = {
= { "ɛ̀ə", "ɛ̀ə.", "ɛ̀ə", "ɛ̀ə.", "ɛ̀ə" },
= { "ḭ", "i.", "i", "i.", "í" },
= { "ɒə", "ɒə", "ɒə", "ɒə", "ɒə" },
= { "ṵ", "u.", "u", "u.", "aoˀ" },
= { "ù", "u", "ū", "u", "u" },
= { "ey", "ɛ", "ɛ", "ɛ", "èy" },
= { "ɔə", "uə", "ɔ̀ə", "ɔə.", "ùə" },
= { "ò", "èə:", "o", "èə:", "ò" },
= { "ɤ̀", "ao", "o‘", "ao", "ò" },
= { "ɔm", "ɔ̀m.", "ɔˀ", "ɔ̀m", "ɔ̀m" },
= { "ɛ̀h", "ah", "ɛ̀h", "ɛ̀h.", "ɛ̀h" },
}
local tone_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
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, " ", "|")
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" .. (#p > 1 and "s" or "") .. ": " ..
tostring( mw.html.create( "span" )
:attr( "lang", "mnw" )
:attr( "class", "mnw" )
: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