local export = {}
local find = mw.ustring.find
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsplit = mw.text.gsplit
local lower = mw.ustring.lower
local upper = mw.ustring.upper
local initialConv = {
= "p", = "t", = "k",
= "pʰ", = "tʰ", = "kʰ",
= "t͡s", = "t͡ɕ",
= "t͡sʰ", = "t͡ɕʰ",
= "m", = "n", = "nʲ", = "ŋ",
= "f", = "s", = "ɕ", = "x",
= "v", = "z",
= "",
}
-- note that 'ir' is for internal use by the code and not used in actual sichuanese pinyin
local finalConv = {
= "z̩", = "ɚ",
= "a", = "o", = "ɛ",
= "ai", = "ei", = "au", = "əu",
= "an", = "ən", = "aŋ", = "oŋ",
= "i", = "ia", = "iɛ",
= "iɛi", = "iau", = "iəu",
= "iɛn", = "in", = "iaŋ",
= "u", = "ua", = "uɛ",
= "uai", = "uei",
= "uan", = "uən", = "uaŋ",
= "y", = "yo", = "ye",
= "yan", = "yn", = "yoŋ",
}
local toneConv = {
= "⁵⁵", = "²¹", = "⁵³", = "²¹³", = "⁻",
}
local initialConv_swz = {
= "g", = "k", = "l", = "n", = "x", = "", = "rh",
}
local finalConv_swz = {
= "", = "r", = "ung", = "uong", = "y", = "iuo", = "ye", = "uan", = "un", = "yng",
}
local function fix(initial, final)
-- ju /tɕy/
if find(initial, '^$') and find(final, '^u') then
final = gsub(final, '^u', 'ü')
end
if initial == 'y' then
initial = ''
if final == 'ou' then
final = 'iu'
elseif not find(final, '^') then -- yin /in/, yuan /yan/, ya /ia/
final = 'i' .. final
end
end
-- wei /uei/ (/-uei/ is usually spelled <-ui> but /uei/ is not <wui>)
-- wu /vu/
-- wai /uai/
-- wen /uən/
if initial == 'w' then
initial = (final == 'u') and 'w' or ''
if final == 'ei' then
final = 'ui'
elseif final == 'en' then
final = 'un'
elseif final ~= 'u' then
final = 'u' .. final
end
end
-- distinguish the two 'i's
if find(initial, '^$') and final == 'i' then
final = 'ir'
end
return initial, final
end
local function warn(initial, final, tone)
if initial == "" and find(final, "^") then
error("Siçuan Pinyin'de heceler i-/u- ile başlamaz. Lütfen y-/w- kullanın.")
end
if not initialConv and initial ~= "y" then
error("Geçersiz başlangıç: " .. initial)
end
if not finalConv and final ~= "uo" then
error("Geçersiz bitiş: " .. final)
end
if tone == "5" then
error("Chengdu artık beşinci vurguya sahip değil. 2'yi kullanın.")
end
end
function export.convert(text, scheme)
if type(text) == "table" then
text, scheme = text.args, text.args
end
local result = {}
for word in gsplit(text, '/') do
local converted = {}
local extra2 = match(word, '^*')
for syllable in gmatch(word, '++*') do
local initial, final, erhua, tone, extra = match(syllable, '^(??)(+)(r?)(+)(*)$')
local caps = false
if find(initial .. final, '') then
caps = true
initial, final = lower(initial), lower(final)
end
warn(initial, final, tone)
initial, final = fix(initial, final)
if final == 'e' and erhua == 'r' then
final, erhua = 'er', ''
end
if scheme == 'IPA' then
initial = initialConv
final = finalConv
tone = gsub(tone, '.', function(char) return toneConv end)
if erhua == 'r' then
if find(final, '^y') then -- 撮口呼
final = 'yɚ'
elseif find(final, '^i') then -- 齊齒呼
final = 'iɚ'
elseif find(final, '^u') then -- 合口呼
final = 'uɚ'
elseif (final == 'o' or final == 'oŋ') and find(initial, '^') then
final = 'ɚ'
elseif final == 'o' or final == 'oŋ' then
final = 'uɚ'
else -- 開口呼
final = 'ɚ'
end
end
syllable = initial .. final .. tone
table.insert(converted, syllable)
elseif scheme == 'SWZ' then
initial = initialConv_swz or initial
final = finalConv_swz or final
tone = gsub(tone, '(%d)%-(%d)', '%2')
-- idk what happens with erhua, so disable output
if erhua == 'r' then return false end
if tone == '3' and (final == 'a' or final == 'ai') then
final = 'a' .. final
end
syllable = initial .. final
if caps then syllable = gsub(syllable, '^.', upper) end
table.insert(converted, '@' .. syllable .. extra)
else
error('Hangi gösterime çevriliyor?')
end
end
if scheme == 'IPA' then
local text = '/' .. table.concat(converted, ' ') .. '/'
table.insert(result, text)
elseif scheme == 'SWZ' then
local text = table.concat(converted, '')
text = gsub(text, '()@(u)', '%1w')
text = gsub(text, '()@(i)', '%1j')
text = gsub(text, '()@(y)', '%1j')
text = gsub(text, '@un', 'wen')
text = gsub(text, '@', '')
table.insert(result, extra2 .. text)
end
end
if scheme == 'IPA' then
return table.concat(result, ', ')
else
return table.concat(result, ' / ')
end
end
return export