মডিউল:zu-IPA
অবয়ব
এই মডিউলের জন্য মডিউল:zu-IPA/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে
local export = {}
local lang = require("Module:languages").getByCode("zu")
local decomp = mw.ustring.toNFD
local find = mw.ustring.find
local gsub = mw.ustring.gsub
local len = mw.ustring.len
local lower = mw.ustring.lower
local recomp = mw.ustring.toNFC
local sub = mw.ustring.sub
local u = mw.ustring.char
local ACUTE = u(0x0301)
local CIRC = u(0x0302)
local MACRON = u(0x0304)
local CARON = u(0x030C)
local SYLL = u(0x0329)
local letters_phonemes = {
-- Vowels
["a"] = "a",
["e"] = "e",
["i"] = "i",
["o"] = "o",
["u"] = "u",
-- Click consonants
["c"] = "ǀ", ["ch"] = "ǀʰ", ["nc"] = "ᵑǀ", ["gc"] = "ᶢǀʱ", ["ngc"] = "ᵑǀʱ",
["q"] = "ǃ", ["qh"] = "ǃʰ", ["nq"] = "ᵑǃ", ["gq"] = "ᶢǃʱ", ["ngq"] = "ᵑǃʱ",
["x"] = "ǁ", ["xh"] = "ǁʰ", ["nx"] = "ᵑǁ", ["gx"] = "ᶢǁʱ", ["ngx"] = "ᵑǁʱ",
-- General consonants
["b"] = "ɓ", ["bh"] = "b", ["mb"] = "mb",
["d"] = "d", ["dl"] = "ɮ",
["f"] = "f",
["g"] = "ɡ", ["ng"] = "nɡ",
["h"] = "h", ["hh"] = "ɦ", ["hl"] = "ɬ",
["j"] = "dʒ", ["nj"] = "ɲdʒ",
["k"] = "ɠ", ["kh"] = "kʰ", ["kl"] = "kx", ["nk"] = "nk", ["k'"] = "k",
["l"] = "l",
["m"] = "m", ["mh"] = "mʱ",
["n"] = "n", ["nh"] = "nʱ", ["nhl"] = "nɬ",
["ny"] = "ɲ",
["p"] = "p", ["ph"] = "pʰ",
["r"] = "r",
["s"] = "s", ["sh"] = "ʃ",
["t"] = "t", ["th"] = "tʰ",
["tsh"] = "tʃ", ["ntsh"] = "ɲtʃ",
["v"] = "v",
["w"] = "w", ["wh"] = "wʱ",
["y"] = "j", ["yh"] = "jʱ",
["z"] = "z",
["-"] = "ʔ",
["m."] = "m" .. SYLL,
["m" .. ACUTE] = "m" .. ACUTE .. SYLL,
['"'] = "ˈ",
[MACRON] = "ː",
[MACRON .. ACUTE] = ACUTE .. "ː",
[CIRC] = CIRC .. "ː",
[CARON] = CARON .. "ː",
}
-- Process penultimate lengthening
local function penultimate_lengthen(term)
-- Do not apply to terms that already have a final long vowel or a stress marker specified
if not (find(term, '"') or find(term, "[āēīōūâêîôûā́ḗī́ṓū́]$")) then
term = require("Module:zu-common").split_syllables(term)
if term[2] then
term[#term - 1] = gsub(term[#term - 1], "[aeiouáéíóú]$", {["a"] = "ā", ["e"] = "ē", ["i"] = "ī", ["o"] = "ō", ["u"] = "ū", ["á"] = "ā́", ["é"] = "ḗ", ["í"] = "ī́", ["ó"] = "ṓ", ["ú"] = "ū́"})
end
term = table.concat(term)
end
return term
end
-- Convert a term to its IPA representation
local function toIPA(term)
term = penultimate_lengthen(term)
local ref = decomp(term)
local result = ""
while len(ref) > 0 do
local matched = false
for length = len(ref), 1, -1 do
local longest_match = sub(ref, 1, length)
if letters_phonemes[longest_match] then
result = result .. letters_phonemes[longest_match]
ref = sub(ref, length + 1)
matched = true
break
end
end
if not matched then
result = result .. sub(ref, 1, 1)
ref = sub(ref, 2)
end
end
return recomp(result)
end
-- Main export function
function export.show(frame)
local args = frame:getParent().args
local term
local tone_needed = ""
if args[1] then
term = lower(args[1])
else
term = lower(mw.title.getCurrentTitle().subpageText)
tone_needed = "<sup title=\"tones missing\">?</sup>"
end
term = toIPA(term)
return require("Module:IPA").format_IPA_full { lang = lang, items = {{pron = "/" .. term .. "/"}} } .. tone_needed
end
return export