Pronunciation/transcription module for Lao. See {{lo-pron}}
for usage.
Testcases: Module:lo-pron/testcases.
local export = {}
local PAGENAME = mw.title.getCurrentTitle().text
local find = mw.ustring.find
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local rhyme
local lang = require("Module:languages").getByCode("lo")
-- for easier processing
local pre = {
= { "ຫງ", "" }, -- faux hng
= { "ຫ", "" }, -- faux hny
= { "ຫນ", "ໜ" },
= { "ຫມ", "ໝ" },
= { "ຫ", "" }, -- faux hl
= { "ຫວ", "" }, -- faux hw
= {"()(?)", "%2%1"},
= {"(.*)()(.*)", "%1%3%2"},
}
local initials = {
= "k", = "kʰ", = "kʰ", = "ŋ", = "ŋ",
= "t͡ɕ", = "s", = "s", = "ɲ", = "ɲ",
= "d", = "t", = "tʰ", = "tʰ", = "n", = "n",
= "b", = "p", = "pʰ", = "pʰ",
= "f", = "f", = "m", = "m",
= "j", = "l", = "l", = "l",
= "ʋ", = "ʋ", = "h", = "h", = "ʔ",
= "kʷ", = "kʷʰ", = "kʷʰ", = "ŋʷ",
= "t͡ɕʷ", = "sʷ", = "sʷ",
= "tʷʰ", = "tʷʰ", = "lʷ", = "ʔʷ", = "hʷ",
}
local vowels = {
= "#",
= "aʔ", = "a", = "aː",
= "iʔ", = "i", = "iː",
= "ɯʔ", = "ɯ", = "ɯː",
= "uʔ", = "u", = "uː",
= "eʔ", = "e", = "eː",
= "ɛʔ", = "ɛ", = "ɛː",
= "oʔ", = "o", = "oː",
= "ɔʔ", = "ɔ", = "ɔː", = "ɔː",
= "ɤʔ", = "ɤ", = "ɤː",
= "uə̯ʔ", = "uːə̯", = "uːə̯", = "uːə̯",
= "iə̯ʔ", = "iə̯ʔ", = "iə̯",
= "iːə̯", = "iːə̯", = "iːə̯", = "iːə̯", = "iːə̯",
= "ɯə̯ʔ", = "ɯə̯", = "ɯːə̯",
= "am", = "aɰ", = "aj", = "aw",
}
local finals = {
= "", = "k̚", = "t̚", = "p̚",
= "ŋ", = "n", = "m",
= "j", = "j", = "w", = "s",
--force final
= "k̚", = "t̚", = "p̚",
= "ŋ", = "n", = "m",
= "j", = "w", = "s",
}
-- Vientiane
local vt_unmarked_tones = { -- M,L,H
live = { "˩(˧)", "˧˥", "˩(˧)" },
dead_short = { "˧˥", "˧", "˧˥" },
dead_long = { "˧˩", "˥˨", "˧˩" },
}
local vt_marked_tones = { -- M,L,H
= { "˧", "˧", "˧" },
= { "˥˨", "˥˨", "˧˩" },
= { "˧˥", "˧˥", "˧˥" },
= { "˩˧", "˩˧", "˩˧" },
}
-- Luang Prabang
local lp_unmarked_tones = { -- M,L,H
live = { "˩˨", "˩˨", "˥˧˧" },
dead_short = { "˩˨", "˧˨", "˩˨" },
dead_long = { "˥˥˨", "˧˦", "˥˥˨" },
}
local lp_marked_tones = { -- M,L,H
= { "˧˨", "˧˨", "˧˨" },
= { "˧˦", "˧˦", "˥˥˨" },
= { "˧˦", "˧˦", "˧˦" },
= { "˩˨", "˩˨", "˩˨" },
}
function export.show(frame)
local accents = {"Vientiane", "Luang Prabang"}
local output = {}
for _,accent in ipairs(accents) do
table.insert(output, toIPA(frame, accent))
end
-- reduced hyphenation (FIXME: Use the standard module)
table.insert(output, "* Hyphenation: <span class='Laoo lo-reading' lang='lo'>" .. (frame:getParent().args or PAGENAME) .. "</span>")
-- global var trick (FIXME: YUCK, clean this up)
local rhymes
if rhyme == "aɰ" then
rhymes = {{rhyme = "aj"}, {rhyme = rhyme}}
elseif rhyme and not find(rhyme, "^#") then
rhymes = {{rhyme = rhyme}}
end
table.insert(output, "* " .. require("Module:rhymes").format_rhymes {
lang = lang,
rhymes = rhymes,
})
return table.concat(output, "\n")
end
function toIPA(frame, accent)
local args = frame:getParent().args
local text = args or PAGENAME -- supports only one pronunciation
local debug = args or nil
local unmarked_tones, marked_tones
if accent == "Vientiane" then
unmarked_tones, marked_tones = vt_unmarked_tones, vt_marked_tones
text = gsub(text, "ໃ", "ໄ")
elseif accent == "Luang Prabang" then
unmarked_tones, marked_tones = lp_unmarked_tones, lp_marked_tones
else
error("The accent " .. accent .. " is not accepted.")
end
local ipa = {}
for syl in mw.text.gsplit(text, "") do
for _, v in ipairs(pre) do
syl = mw.ustring.gsub(syl, v, v)
end
local i, v, f, t = mw.ustring.match(syl, "^(?)('?*)(%+??)(?)$")
if find(i, ".$") then
error("The -ຣ-, -ລ- medials are either unpronounced or disyllabic. Please respell.")
end
if find(i, "^ວ?$") then -- middle class
tn = 1
elseif find(i, "^ວ?$") then -- low class
tn = 2
else --high class
tn = 3
end
if find(i, ".ວ$") then
if v == "" then
i = sub(i, 1, -2)
v = "ວ"
elseif v == "ຍ" then
i = sub(i, 1, -2)
v = "ວ"
f = "ຍ"
elseif v == "າ" then -- Cwaa > Cuua
i = sub(i, 1, -2)
v = "ວ"
elseif v == "າຍ" then -- Cwaa > Cuua
i = sub(i, 1, -2)
v = "ວ"
f = "ຍ"
end
end
if find(v, "ວ$") and v ~= "ົວ" and v ~= "ວ" and v ~= "'ວ" then
v = sub(v, 1, -2)
f = "ວ"
end
if find(v, "ຍ$") and v ~= "ເຍ" and v ~= "ເັຍ" and v ~= "'ຍ" then
v = sub(v, 1, -2)
f = "ຍ"
end
if find(v, "ຽ$") and v ~= "ັຽ" and v ~= "ເັຽ" and v ~= "ຽ" and v ~= "'ຽ" then
v = sub(v, 1, -2)
f = "ຍ"
end
if f == "" and (v == "ິ" or v == "ຶ" or v == "ຸ" or v == "ເິ" or v == "ເຶອ") then
v = v .. "*" -- added ʔ
end
if t ~= "" then
tm = marked_tones
else
dead = (find(f, "%+?") or find(vowels, "ʔ$"))
long = find(vowels, "ː")
tm = unmarked_tones
end
if debug then
table.insert(ipa, "")
else
table.insert(ipa, initials .. vowels .. finals .. tm)
rhyme = vowels .. finals -- It becomes rhyme after the last iteration
end
end
local ipa_final = table.concat(ipa, ".")
ipa_final = gsub(ipa_final, "a(ʔ+)%.", "a(%1).")
ipa_final = ""
return "* " .. require("Module:IPA").format_IPA_full {
lang = lang,
items = {{pron = ipa_final}},
a = {accent},
} .. (#ipa > 0 and require("Module:utilities").format_categories("Lao " .. #ipa .. "-syllable words", lang) or "")
end
return export