À pour but de convertir du Jyutping vers n'importe quel autre transcription phonétique du cantonais. Actuellement : Jyutping-vers-API, Jyutping-vers-Yale, Jyutping-vers-Pinyin cantonais, Jyutping-vers-Romanisation du Guangdong.
local export = {}
local ugsub = mw.ustring.gsub
local split = mw.text.split
local entering_tones = {
= "7", = "8", = "9"
}
local ipa_preprocess = {
= {"a", "ă"}, = {"yu", "y"}, = {"ăă", "a"}, = {"uk", "ŭk"}, = {"ik", "ĭk"},
= {"ou", "ŏu"}, = {"eoi", "eoy"}, = {"ung", "ŭng"}, = {"ing", "ĭng"}, = {"ei", "ĕi"}
}
local ipa_initial = {
= "p", = "pʰ", = "m", = "f",
= "t", = "tʰ", = "n", = "l",
= "k", = "kʰ", = "ŋ", = "kʷ", = "kʷʰ",
= "t͡ɕ", = "t͡ɕʰ", = "ɕ",
= "t͡s", = "t͡sʰ", = "s",
= "h", = "w", = "j",
= ""
}
local ipa_nucleus = {
= "ɑː", = "ɐ",
= "ɛː", = "e",
= "iː", = "ɪ",
= "ɔː", = "o",
= "œː", = "ɵ",
= "uː", = "ʊ",
= "yː"
}
local ipa_coda = {
= "i̯", = "u̯", = "y̯",
= "m", = "n", = "ŋ",
= "p̚", = "t̚", = "k̚",
= ""
}
local ipa_tone = {
= "<span style=\"cursor:help\" title=\"or 53\">⁵⁵</span>",
= "³⁵",
= "³³",
= "²¹",
= "¹³",
= "²²",
= "⁵",
= "³",
= "²",
= ""
}
local ipa_tone_sandhi = {
= "⁻", = "⁻", = ""
}
local ipa_syllabic = {
= "m̩", = "ŋ̍"
}
local acute_accents = {
= "á", = "é", = "í", = "ó", = "ú"
}
local grave_accents = {
= "à", = "è", = "ì", = "ò", = "ù"
}
local macrons = {
= "ā", = "ē", = "ī", = "ō", = "ū"
}
local yale_final = {
= "a", = "沒有耶魯拼音", = "沒有耶魯拼音", = "沒有耶魯拼音", = "沒有耶魯拼音",
= "eu", = "eung", = "euk", = "eui", = "eun", = "eut",
= ""
}
local canton_pinyin_regex = {
= "y", = "oe", = "oey", = "dz%1", = "ts%1",
)()"]=function(a,b) return a .. entering_tones end,
)()$"]=function(a,b) return a .. entering_tones end
}
local function yale_tone(final,b)
if b == "4" or b == "5" or b == "6" then
final = final:gsub("(?g?)$", "h%1", 1)
end
if b == "1" then final = final:gsub("", macrons, 1) end
if b == "4" then final = final:gsub("", grave_accents, 1) end
if b == "2" or b == "5" then final = final:gsub("", acute_accents, 1) end
return final
end
function export.jyutping_to_ipa(text)
if type(text) == "table" then text = text.args end
if text:find("") then error("Ton invalide en Jyutping.") end
if text:find("") then error("Ne pas mettre de capitales au Jyutping.") end
if text:find("%-") then error("Ne pas mettre de trait d’union au Jyutping.") end
if text:find("") then error("Erreur dans la transcription en Jyutping.") end
text = text:lower()
text = text:gsub("jy()", "j%1")
text = text:gsub("%.%.%.", " ")
text = text:gsub(",", "隔"):gsub("隔 ", ", ")
local reading = split(text, "隔")
local function retrieve_ipa1(a,b,c,d,e)
return ipa_initial .. ipa_syllabic .. ipa_tone .. ipa_tone_sandhi .. ipa_tone
end
local function retrieve_ipa2(a,b,c,d,e,f)
return (ipa_initial or error(("Initiale non-reconnu : \"%s\""):format(a))) ..
(ipa_nucleus or error(("Noyau non-reconnu : \"%s\""):format(b))) ..
(ipa_coda or error(("Coda non-reconnu : \"%s\""):format(c))) ..
(ipa_tone or error(("Ton non-reconnu : \"%s\""):format(d))) ..
ipa_tone_sandhi ..
(ipa_tone or error(("Ton non-reconnu : \"%s\""):format(f)))
end
local function get_entering_tone(a,b) return a .. entering_tones end
for i = 1,#reading do
reading = reading:gsub("()", "%1 "):gsub("", "")
local syllable = split(reading:lower(), " ")
for i = 1,#syllable do
syllable = syllable:gsub("()yu", "%1hyu")
syllable = syllable:gsub("()oe", "%1hoe")
syllable = syllable:gsub("()eo", "%1heo")
if (not syllable:find("^??+?g???$") and not syllable:find("^h?g???$")) and syllable:find("") then
error("Format Jyutping incorrect. Veuillez vérifiez s'il vous plaît !")
end
syllable = syllable:gsub("^(h?)(g?)()(?)(?)$", retrieve_ipa1)
syllable = syllable:gsub("()()", get_entering_tone)
syllable = syllable:gsub("()()$", get_entering_tone)
for regex_idx,regex_pair in ipairs(ipa_preprocess) do
syllable = ugsub(syllable,regex_pair,regex_pair)
end
syllable = ugsub(syllable, "spăn", "span")
syllable = ugsub(syllable,
"(??)(?)(?g?)()(?)(?)",
retrieve_ipa2)
end
reading = table.concat(syllable, " ")
end
return table.concat(reading, "/, /")
end
function export.jyutping_to_yale(text)
if type(text) == "table" then text = text.args end
text = text:gsub("jy()", "j%1")
text = text:gsub(",", "隔"):gsub("隔 ", ", ")
local reading = split(text, "隔")
local function yale_tone2(a, b) return yale_tone((yale_final or a), b) end
for i = 1,#reading do
reading = reading:gsub("%-", "")
reading = reading:gsub("()", "%1 ")
local syllables = split(mw.ustring.lower(reading), " ",true)
for j = 1,#syllables do
local text = syllables
if text:find("jy") then error("mauvaise utilisation de 'jy' en Jyutping") end
text = text:gsub("",{ = "1", = "3", = "6"})
text = text:gsub("^m$",{ = "{{懸停|或m̀|m̄}}", = "ḿ", = "m", = "m̀h", = "ḿh", = "mh"})
text = text:gsub("^ng$",{ = "{{懸停|或ǹg|n̄g}}", = "ńg", = "ng", = "ǹgh", = "ńgh", = "ngh"})
text = text:gsub("jy?", "y")
text = text:gsub("",{ = "j", = "ch"})
text = text:gsub("(???)()", yale_tone2)
text = text:gsub("(yu?)()", yale_tone)
text = ugsub(text, "",{ = "{{懸停|或à|ā}}", = "{{懸停|或è|ē}}", = "{{懸停|或ì|ī}}", = "{{懸停|或ò|ō}}", = "{{懸停|或ù|ū}}"})
text = text:gsub("{{懸停|或(+)|(+)}}", '<span style="cursor:help" title="or %1">%2</span>')
syllables = text
end
reading = table.concat(syllables, " ")
if reading:find("沒有耶魯拼音") then
reading = "sons familliers non définis"
end
end
return table.concat(reading, ", ")
end
function export.jyutping_to_cantonese_pinyin(text)
if type(text) == "table" then text = text.args end
text = text:gsub("jy()", "j%1")
text = text:gsub(",", "隔"):gsub("隔 ", ", ")
local reading = split(text, "隔")
for i=1,#reading do
for regex, replace in pairs(canton_pinyin_regex) do
reading = ugsub(reading, regex, replace)
end
end
return table.concat(reading, ", ")
end
function export.jyutping_to_guangdong(text)
if type(text) == 'table' then text = text.args end
local palatal = { ='j', ='q', ='x' }
local function palatalize(a,b) return palatal .. b end
local final = { ='b', ='g', ='d' }
local function get_final(a,b) return final .. b end
text = text:gsub(",", "隔"):gsub("隔 ", ", ")
local reading = split(text, "隔")
for i, item in ipairs(reading) do
item = item:gsub('yu', 'ü')
item = item:gsub('eoi', 'êü')
item = item:gsub('j', 'y')
item = item:gsub('', 'ê')
item = item:gsub('e', 'é')
item = ugsub(item, '()()', palatalize)
item = ugsub(item, '()ü', '%1u')
item = item:gsub('a+', { ='a', ='e' } )
item = item:gsub('()w', '%1u')
item = item:gsub('()u', '%1o')
item = item:gsub('()(%d)', get_final)
item = item:gsub('%d%-(%d)', '%1')
if item:find('é') then
item = 'sons familliers non définis'
end
reading = item
end
return table.concat(reading, ", ")
end
function export.jyutping_format(text)
if type(text) == "table" then text = text.args end
if text:find("%[%[") then
return "juste un text long, afin de s'assurer qu'il fonctionne"
end
text = split(text:gsub(",", "隔"):gsub("隔 ", ", "), "隔")
for i, to_be_processed in ipairs(text) do
text = to_be_processed:gsub("%-()", "%1")
end
return text
end
function export.hoisanva_to_ipa(text)
local hsv_initial = {
= "p", = "pʰ", = "ᵐb", = "f", = "v",
= "t", = "tʰ", = "ⁿd", = "l", = "ɬ",
= "k", = "kʰ", = "ᵑg",
= "t͡s", = "t͡sʰ",
= "ʒ", = "s", = "h", = ""
}
local hsv_final = {
= "a", = "ai", = "au", = "am",
= "an", = "aŋ", = "ap̚", = "at̚",
= "ak̚",
= "i", = "iu", = "im", = "in",
= "ip̚", = "it̚",
= "iɛ", = "iau", = "iam", = "iaŋ",
= "iap̚", = "iak̚",
= "u", = "ui", = "un", = "ut̚",
= "ei", = "eu", = "em", = "en",
= "ɵŋ", = "ep̚", = "et̚", = "ɵk̚", = "ɵt̚",
= "ᵘɔ", = "ᵘɔi", = "ᵘɔn", = "ɔŋ",
= "ᵘɔt̚", = "ɔk̚",
= "m̩"
}
local hsv_tone = { "³³", "⁵⁵", "²²", "²¹", "³²" }
local gsplit = mw.text.gsplit
local result = {}
for word in gsplit(text, ",") do
local initial, final, tone, tone_ch, word_result = "", "", "", "", {}
for syllable in gsplit(word, " ") do
initial, final, tone, tone_ch = syllable:match("^(*)(*)()(??%*?)$")
if final == "" then final, initial = initial, "" end
if not hsv_initial or not hsv_final or not hsv_tone or (tone == "2" and tone_ch == "*") then
error("La syllable '" .. syllable .. "' n'est pas vailde pour une conversion API.")
end
table.insert(word_result,
hsv_initial .. hsv_final .. hsv_tone ..
(tone_ch ~= "" and "⁻" or "") ..
(tone_ch == "*" and hsv_tone or (tone_ch:find("^%-") and hsv_tone or "")) ..
(tone_ch:sub(-1, -1) == "*" and "⁵" or ""))
end
table.insert(result, table.concat(word_result, " "))
end
return "/" .. table.concat(result, "/, /") .. "/"
end
return export