For use in {{ny-IPA}}
.
local m_IPA = require("Module:IPA")
local export = {}
local consonants = {
= "ɓ", = "ɗ", = "w⁽ᵝ⁾",
= "ʰ", = "ʷ", = "ʲ",
= "ɽ", = "ɽ",
= "d͡ʒ",
= "ɡ"
}
local vowels = {"a", "e", "i", "o", "u", "á", "é", "í", "ó", "ú", "ń", "m'", "ḿ"}
local pre_replacements = {
= "a(w)u", = "e(w)u", = "i(w)u", = "o(w)a", = "u(w)a",
= "á(w)u", = "é(w)u", = "í(w)u", = "ó(w)a", = "ú(w)a",
= "a(w)ú", = "e(w)ú", = "i(w)ú", = "o(w)á", = "u(w)á",
= "á(w)ú", = "é(w)ú", = "í(w)ú", = "ó(w)á", = "ú(w)á"
}
local trigraphs = { = "t͡ʃʰ",
= "ⁿdz",
= "(w)",
}
local digraphs = { = "t͡ʃ",
= "ʃ",
= "ʒ",
= "d͡z",
= "d͡z",
= "t͡s",
= "ʷʰ",
= "ʲʰ",
= "m",
= "b",
= "d",
= "ḿ'p",
= "p͡f",
= "b͡v"}
local nasals = { = "ᵐb", = "ᵐp",
= "ᶬv", = "ᶬf",
= "ⁿd", = "ⁿt",
= "ᵑɡ", = "ŋ", = "ᵑk",
= "ⁿd͡ʒ",
= "ⁿt͡ʃ",
= "ɲ",
= "psʲ",
= "bzʲ",
= "ᵐb",
= "ⁿz",
= "ⁿs",
}
local syllable_ends = {}
for k,v in ipairs(vowels) do
syllable_ends = v .. " "
end
-- remove spaces from the end of a string
function rtrim(s)
local n = #s
while n > 0 and s:find("^%s", n) do n = n - 1 end
return s:sub(1, n)
end
function export.IPA(text)
text = rtrim(text)
text = mw.ustring.lower(text)
text = mw.ustring.gsub(text, "%-", "")
-- if text contains spaces, recursively computer IPA for each part
if (mw.ustring.match(text, "%s")) then
local result = {}
for i in mw.ustring.gmatch(text, '(+)') do
table.insert(result, mw.ustring.sub(export.IPA(i),2,-2))
end
return "/"..table.concat(result, " ").."/"
end
for k1,replacement in pairs(pre_replacements) do
text = mw.ustring.gsub(text, k1, replacement)
end
text = mw.ustring.gsub(text, "m'", "m' ")
text = mw.ustring.gsub(text, ".", syllable_ends)
text = rtrim(text)
local syllables = mw.text.split(text, " ", true)
local result = {}
for k1,syllable in ipairs(syllables) do
local ipa = syllable
ipa = mw.ustring.gsub(ipa, ".", consonants)
for k2,trigraph in pairs(trigraphs) do
ipa = mw.ustring.gsub(ipa, k2, trigraph)
end
for k2,digraph in pairs(digraphs) do
ipa = mw.ustring.gsub(ipa, k2, digraph)
end
for k2,nasal in pairs(nasals) do
ipa = mw.ustring.gsub(ipa, k2, nasal)
end
local first = mw.ustring.sub(ipa, 1, 1)
if (first == "ʰ") then
ipa = "h"..mw.ustring.sub(ipa,2)
end
if (first == "ʲ") then
ipa = "j"..mw.ustring.sub(ipa,2)
end
if (first == "ʷ") then
ipa = "w"..mw.ustring.sub(ipa,2)
end
table.insert(result, ipa)
end
if (#result >= 2) then
local penultimate = result
local first = mw.ustring.sub(penultimate, 1, 2)
if (first ~= "ḿ'") then
penultimate = "ˈ"..penultimate
end
result = penultimate
end
result = table.concat(result, ".")
result = mw.ustring.gsub(result, "'", "ˈ")
result = mw.ustring.gsub(result, "%.ˈ", "ˈ")
if (mw.ustring.sub(result, 1, 1) == ".") then result = mw.ustring.sub(result, 2) end
result = "/" .. result .. "/"
return result
end
function export.show(frame)
local params = {
= {default = mw.title.getCurrentTitle().text, list=true}
}
local args = require("Module:parameters").process(frame:getParent().args, params)
lang = require("Module:languages").getByCode("ny")
local items = {}
for _,text in ipairs(args) do
table.insert(items, {pron = export.IPA(text), note = nil})
end
local text = args
return m_IPA.format_IPA_full { lang = lang, items = items }
end
return export