မဝ်ဂျူ:tg-IPA
Documentation for this module may be created at မဝ်ဂျူ:tg-IPA/doc
local export = {}
local rsubn = mw.ustring.gsub
local m_a = require("Module:accent_qualifier")
local m_IPA = require("Module:IPA")
local ulower = mw.ustring.lower
local lang = require("Module:languages").getByCode("tg")
function export.show(frame)
local args = frame:getParent().args
local p, results = {}, {}
if args[1] then
for index, item in ipairs(args) do
table.insert(p, (item ~= "") and item or nil)
end
else
if mw.title.getCurrentTitle().nsText == "Template" then
p = {"чаҳоршанбе"}
else
p = {mw.title.getCurrentTitle().text}
end
end
for _, word in ipairs(p) do
table.insert(results, {pron = "/" .. export.to_IPA(word) .. "/"})
end
return "* " .. m_IPA.format_IPA_full(lang, results)
end
local consonants = {
['б'] = 'b',
['д'] = 'd',
['ҷ'] = 'd͡ʒ',
['ф'] = 'f',
['ф'] = 'f',
['т'] = 't',
['ғ'] = 'ɣ',
['қ'] = 'q',
['ҳ'] = 'h',
['й'] = 'j',
['к'] = 'k',
['л'] = 'l',
['м'] = 'm',
['г'] = 'ɡ',
['н'] = 'n',
['п'] = 'p',
['р'] = 'ɾ',
['с'] = 's',
['ш'] = 'ʃ',
['ч'] = 't͡ʃ',
['в'] = 'v',
['х'] = 'x',
['з'] = 'z',
['ж'] = 'ʒ',
['ъ'] = 'ʔ'
}
local vowels = {
['а'] = 'æ',
['о'] = 'ɔ',
['и'] = 'i',
['е'] = 'e',
['у'] = 'u',
['ӯ'] = 'ɵ',
['ӣ'] = 'i',
['ё'] = 'jɔ',
['э'] = 'e',
['ю'] = 'ju',
['я'] = 'jæ',
}
function export.to_IPA(text)
text = rsubn(text, "[-.,]", " ")
text = ulower(text)
text = rsubn(text, " | ", "# | #")
text = "##" .. rsubn(text, " ", "# #") .. "##"
text = rsubn(
text,
"([аоуэяёюиӣе][́̀]?)([еиӣ])",
function(a, e)
local iotated = {
['е'] = 'je',
['и'] = 'ji',
['ӣ'] = 'ji',
}
return a .. iotated[e]
end
)
-- Replace vowels
text = rsubn(text, ".", vowels)
-- Replace consonants
text = rsubn(text, ".", consonants)
text = rsubn(text, "#e", "#je")
text = rsubn(text, "#", "")
return text
end
return export