Pronunciation module for Tibetan. See {{bo-IPA}}
.
local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
function export.tidyRom(text)
text = gsub(text, "()(.?)", function(a, b) if b == "-" or b == "" or b == " " or b == "," then return "<sup>"..a.."</sup>"..b end end)
return text
end
local iConv = {
= "p", = "pʰ", = "b",
= "t", = "tʰ", = "d",
= "c", = "cʰ", = "ɟ",
= "k", = "kʰ", = "g",
= "t͡s", = "t͡sʰ", = "d͡z",
= "ʈ͡ʂ", = "ʈ͡ʂʰ", = "ɖ͡ʐ",
= "t͡ɕ", = "t͡ɕʰ", = "d͡ʑ",
= "m", = "n", = "ȵ", = "ŋ",
= "m̥", = "ŋ̊", --limited
= "l", = "ɬ",
= "f", = "s", = "h",
= "ʂ", = "ɕ", = "ç",
= "ʐ",
= "w", = "j",
= "ʔ",
}
local fConv = {
= "i", = "e", = "a", = "ə", = "o", = "u",
= "iː", = "eː", = "aː", = "əː", = "oː", = "uː",
= "ɛː", = "øː", = "yː", = "ɪː", = "ʊː",
= "iu", = "eu", = "əu",
= "ao", = "ua", = "ei", = "io",
= "im", = "em", = "am", = "əm", = "om", = "um",
= "ĩ", = "ẽ", = "an", = "on", = "un",
= "ɛ̃", = "ø̃", = "ỹ",
= "iŋ", = "eŋ", = "aŋ", = "əŋ", = "oŋ", = "uŋ",
= "ip̚", = "ep̚", = "ap̚", = "əp̚", = "op̚", = "up̚",
= "i(k̚)ˀ", = "e(k̚)ˀ", = "ə(k̚)ˀ", = "a(k̚)ˀ", = "o(k̚)ˀ", = "u(k̚)ˀ",
= "iː(ɹ)", = "eː(ɹ)", = "aː(ɹ)", = "oː(ɹ)", = "uː(ɹ)",
}
local tConv = {
= "˥˥",
= "˥˨",
= "˩˨",
= "˩˧˨",
= "ˑ",
}
function export.ipa(text)
text = mw.ustring.lower(text)
for word in mw.ustring.gmatch(text, "(+)") do
local originalWord = word
word = gsub(word, "^(*)(*)(?)$", function(initial, final, tone)
return (iConv or initial) .. (fConv or final) .. tConv end)
text = gsub(text, originalWord, word, 1)
end
text = gsub(text, "-", ".")
return text
end
function ipaFormat(word, no_intro)
local part = mw.text.split(word, ",")
return (no_intro and "" or "]<sup>(])</sup>: ") ..
'<span class=\"IPA\">/' .. table.concat(part, "/, /") .. '/</span>'
end
function export.show(frame)
local args = frame:getParent().args
local p, ipa, textShow, textHide = {}, {}, "", ""
if args ~= "-" then
local otb_ipa = {}
local lang = require("Module:languages").getByCode("bo")
local page_title = lang:transliterate(args or mw.title.getCurrentTitle().text)
if page_title then
local single_letter = {
= "ġ", = "ċ", = "ṫ", = "ṗ",
= "ŋ", = "ñ",
= "ʒ", = "ž",
= "ż", = "ṡ"
}
local voiceless_lateral = {
= "ĺ", = "ŕ"
}
local function voice(text)
return match(text, "") and "voiceless" or "voiced"
end
local base_ipa = {
= "ɡ", = "kʰ",
= "t͡ɕ", = "t͡ɕʰ", = "d͡ʑ", = "ȵ",
= "tʰ",
= "pʰ",
= "t͡s", = "t͡sʰ", = "d͡z",
= "ʑ", = "ɣ",
= "j",
= "ɕ",
= "l̥", = "r̥"
}
local syllable_structure = "^(b?)(?)(%.?)()(?)(w?)()(?)(?)$"
local voicing = { = "z" }
local devoicing = { = "p", = "t", = "k" }
local function initial_process(prefix, superscript, base)
local prenasal = { = "ᵑ", = "ⁿ", = "ᵐ" }
if superscript == "'" then
for ensuing, nasal in pairs(prenasal) do
superscript = match(base, "") and nasal or superscript
end
end
return gsub(prefix .. superscript, ".", (voice(base) == "voiced" and voicing or devoicing)) .. (base_ipa or base)
end
local function vowel_process(glide_a, glide_b, vowel, sep)
local glide_ipa = { = "ʲ", = "ʷ" }
local glide_sep_ipa = { = "j", = "ʷ" }
local vowel_ipa = { = "ᵻ" }
return gsub(gsub(glide_a .. glide_b, ".", sep ~= "." and glide_ipa or glide_sep_ipa), "rʷ", "ʷr") .. gsub(vowel, ".", vowel_ipa)
end
local function coda_process(coda, suffix)
coda = gsub(coda, "'", "(ɣ)")
return (devoicing or coda) .. suffix
end
page_title = gsub(page_title, "tsh", "ǯ")
for original, replaced in pairs(single_letter) do
page_title = gsub(page_title, original, replaced)
end
page_title = gsub(page_title, "", voiceless_lateral)
for syllable in mw.text.gsplit(page_title, " ") do
syllable = gsub(syllable, "^()", "ʔ%1")
if match(syllable, syllable_structure) then
syllable = gsub(syllable, syllable_structure, function(prefix, superscript, sep, base, glide_a, glide_b, vowel, coda, suffix)
if match(base, "") and glide_a .. glide_b == "" and prefix .. superscript ~= "" then
glide_a, glide_b = match(base, "") or "", match(base, "w") or ""
base = prefix .. superscript
prefix, superscript = "", ""
end
return
initial_process(prefix, superscript, base) ..
vowel_process(glide_a, glide_b, vowel, sep) ..
coda_process(coda, suffix)
end)
table.insert(otb_ipa, syllable)
else
erroneous = true
break
end
end
textShow = textShow .. "\n* ]: " .. ipaFormat("*" .. table.concat(otb_ipa, "."), true)
textHide = textHide .. (not erroneous and "* ]:\n** " .. ipaFormat("*" .. table.concat(otb_ipa, ".")) .. " <span style=\"font-size:80%\">(reconstructed)</span>" or "")
end
end
if args then
for index, item in ipairs(args) do
table.insert(p, (item ~= "") and item or nil)
end
for _, transcription in ipairs(p) do
table.insert(ipa, export.ipa(transcription))
end
textShow = textShow .. "\n* ]: " .. ipaFormat(table.concat(ipa, ","), true)
textHide = textHide .. "\n* ]" ..
"\n** ]: <span style=\"font-family:monospace;\" class=\"tr\">" .. export.tidyRom(table.concat(p, ", ")) .. "</span>" ..
"\n** ('']'') " .. ipaFormat(table.concat(ipa, ","))
end
if args or args then
textHide = textHide .. "\n* ]"
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
end
if args or args or args or args or args then
textHide = textHide .. "\n* ]"
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
end
if args then
textShow = textShow .. "\n* ]: " .. ipaFormat(args, true)
textHide = textHide .. "\n* ]"
textHide = textHide .. "\n** ('']'') " .. ipaFormat(args)
end
return '<div class="standard-box mw-collapsible mw-collapsed" style="max-width:400px; font-size:100%">' .. textShow ..
'\n<div class="mw-collapsible-content">\n----\n' .. textHide .. '</div></div>'
end
return export