This module is not to be directly used. It is used by Template:yo-IPA, see there for usage. While it works for the vast majority of words, the code still needs to be cleaned up.
All tests passed. (refresh)
Text | Expected | Actual | Comments | |
---|---|---|---|---|
Adébáyọ̀ | ā.dé.bá.jɔ̀ | ā.dé.bá.jɔ̀ | ||
ẹẹ́sàn-ándínláàádọ́sàn-án | ɛ̄ɛ́.sã̀ã́.dĩ́.láàá.dɔ́.sã̀ã́ | ɛ̄ɛ́.sã̀ã́.dĩ́.láàá.dɔ́.sã̀ã́ | ||
Ẹ káàárọ̀ | ɛ̄ káàá.ɾɔ̀ | ɛ̄ káàá.ɾɔ̀ | ||
kò | kò | kò | ||
kọ̀m̀pútà | kɔ̀.ŋ̀.k͡pú.tà | kɔ̀.ŋ̀.k͡pú.tà | ||
nàá | nã̀ã́ | nã̀ã́ | ||
oghó | ō.ɣó | ō.ɣó | ||
sẹngwà | sɛ̃̄.ɡʷà | sɛ̃̄.ɡʷà | ||
ụ̀ṣà | ʊ̀.ʃà | ʊ̀.ʃà | ||
ị̀kàrà | ɪ̀.kà.ɾà | ɪ̀.kà.ɾà | ||
n̄ǹkan | ŋ̄ŋ̀.kã̄ | ŋ̄ŋ̀.kã̄ | ||
Ṣáínà | ʃá.í.nà | ʃá.í.nà | ||
Yorùbá | jō.ɾù.bá | jō.ɾù.bá | ||
márùn-ún | má.ɾũ̀ṹ | má.ɾũ̀ṹ | ||
ẹ̀ẹ́dẹ́gbẹ̀rùn-ún lọ́ná | ɛ̀ɛ́.dɛ́.ɡ͡bɛ̀.ɾũ̀ṹ lɔ́.nã́ | ɛ̀ɛ́.dɛ́.ɡ͡bɛ̀.ɾũ̀ṹ lɔ́.nã́ | ||
lálá | lá.lá | lá.lá | ||
lálá | lá.ꜜlá | lá.ꜜlá |
local gsub = mw.ustring.gsub
local lower = mw.ustring.lower
local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local u = require("Module:string/char")
local export = {}
local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("yo")
-- apply rsub() repeatedly until no change
local function gsub_repeatedly(term, foo, bar)
while true do
local new_term = gsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
local MACRON = u(0x0304) -- macron = ̄
local DOT = u(0x0323) -- dot = ̣
local NASAL = u(0x0303) -- nasal = ̃
local consonants = {
= "b",
= "d",
= "f",
= "ɡ",
= "ɡ͡b",
= "h",
= "d͡ʒ",
= "k",
= "l",
= "m",
= "n",
= "k͡p",
= "ɾ",
= "s",
= "ʃ",
= "t",
= "w",
= "j",
= "ɣ",
= "ɡʷ",
}
local vowels = {
= "a",
= "e",
= "ɛ",
= "i",
= "o",
= "ɔ",
= "u",
= "ɪ",
= "ʊ",
}
local nasals = {
= "ã",
= "ɛ̃",
= "ĩ",
= "ɔ̃",
= "ũ",
= "m",
= "ŋ",
}
function export.IPA(text, loanword, downstep)
text = lower(text)
text = gsub(text, "%-", "z")
text = toNFD(text)
text = gsub(text, ".", {
= "ẹ",
= "ọ",
= "ṣ",
= "ị",
= "ụ",
})
text = text .. "x"
text = gsub(text, "%s+", " ")
text = gsub(text, "^ ", "")
text = gsub(text, " $", "")
text = gsub(text, "\n", "")
text = gsub(text, "'", "")
text = gsub(text, "ẹ", "ɛ")
text = gsub(text, "gb", "ɡ͡b")
text = gsub(text, "gh", "ɣ")
text = gsub(text, "gw", "ɡʷ")
text = gsub(text, "g", "ɡ")
text = gsub(text, "ị", "ɪ")
text = gsub(text, "j", "d͡ʒ")
text = gsub(text, "ọ", "ɔ")
text = gsub(text, "p", "k͡p")
text = gsub(text, "r", "ɾ")
text = gsub(text, "ṣ", "ʃ")
text = gsub(text, "ụ", "ʊ")
text = gsub(text, "y", "j")
text = gsub(text, "m()", "ŋ" .. "%1")
text = gsub(text, "n()", "ŋ" .. "%1")
text = gsub_repeatedly(text, "()()", "%1" .. MACRON .. "%2")
text = gsub(text, "()()n()", "%1" .. NASAL .. "%2%3")
--TODO: FIX LOANWORDS
if not loanword then
text = gsub(text, "n()()", "n%1" .. NASAL .. "%2")
end
if not loanword then
text = gsub(text, "m()()", "m%1" .. NASAL .. "%2")
end
text = gsub_repeatedly(text, "()()()()()", "%1%2%3%4" .. NASAL .. "%5")
text = gsub(text, "()()", "%1" .. "%2")
text = gsub(text, "a()()za","a" .. "%1" .. "%2a")
text = gsub(text, "ɛ()()zɛ","ɛ" .. "%1" .. "%2ɛ")
text = gsub(text, "i()()zi","i" .. "%1" .. "%2i")
text = gsub(text, "ɪ()()zɪ","ɪ" .. "%1" .. "%2ɪ")
text = gsub(text, "ɔ()()zɔ","ɔ" .. "%1" .. "%2ɔ")
text = gsub(text, "u()()zu","u" .. "%1" .. "%2u")
text = gsub(text, "ʊ()()zʊ","ʊ" .. "%1" .. "%2ʊ")
text = gsub(text, "z", ".")
-- Split into syllables
text = gsub(text, "a()()","a" .. "%1.%2")
text = gsub(text, "a()()()","a" .. "%1" .. "%2.%3")
text = gsub(text, "e()()","e" .. "%1.%2")
text = gsub(text, "ɛ()()","ɛ" .. "%1.%2")
text = gsub(text, "ɛ()()()","ɛ" .. "%1" .. "%2.%3")
text = gsub(text, "i()()","i" .. "%1.%2")
text = gsub(text, "i()()()","i" .. "%1" .. "%2.%3")
text = gsub(text, "ɪ()()","ɪ" .. "%1.%2")
text = gsub(text, "ɪ()()()","ɪ" .. "%1" .. "%2.%3")
text = gsub(text, "o()()","o" .. "%1.%2")
text = gsub(text, "ɔ()()","ɔ" .. "%1.%2")
text = gsub(text, "ɔ()()()","ɔ" .. "%1" .. "%2.%3")
text = gsub(text, "u()()","u" .. "%1.%2")
text = gsub(text, "u()()()","u" .. "%1" .. "%2.%3")
text = gsub(text, "ʊ()()","ʊ" .. "%1.%2")
text = gsub(text, "ʊ()()()","ʊ" .. "%1" .. "%2.%3")
text = gsub_repeatedly(text, "m()()","m" .. "%1.%2")
text = gsub_repeatedly(text, "ŋ()()","ŋ" .. "%1.%2")
text = gsub(text, "x", "")
-- Adds downstep ꜜ before provided syllable
if downstep then
downstep = tonumber(downstep)
local i = 0
local result = (text):gsub("+", function(syllable)
i = i + 1
if i == downstep then
return "ꜜ" .. syllable
end -- else leave it alone
end)
text = result
end
return toNFC(text)
end
function export.show(frame)
local args = frame:getParent().args
local p, results = {}, {}
if args then
for _, item in ipairs(args) do
table.insert(p, (item ~= "") and item or nil)
end
else
error("Please provide a tone marked term.")
end
for _, text in ipairs(p) do
if args == "1" then
table.insert(results, {pron = "/" .. export.IPA(text, true, args) .. "/", note = nil})
else
table.insert(results, {pron = "/" .. export.IPA(text, false, args) .. "/", note = nil})
end
end
return m_IPA.format_IPA_full { lang = lang, items = results }
end
return export