Bước tới nội dung

Mô đun:ce-IPA

Từ điển mở Wiktionary
local export = {}
local PAGENAME = mw.title.getCurrentTitle().text
local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("ce")

local scripts_IPA_single = {
	["а"] = "a", ["б"] = "b", ["в"] = "u̯", ["г"] = "ɡ", ["д"] = "d", ["е"] = "e", ["ё"] = "jo", ["ж"] = "ʒ", 
	["з"] = "z", ["и"] = "ı̇", ["й"] = "i̯", ["к"] = "k", ["л"] = "l", ["м"] = "m", ["н"] = "n", ["о"] = "o", 
	["п"] = "p", ["р"] = "r", ["с"] = "s", ["т"] = "t", ["у"] = "u", ["ф"] = "f", ["х"] = "x", ["ц"] = "t͡s", 
	["ч"] = "t͡ʃ", ["ш"] = "ʃ", ["щ"] = "ʃt͡ʃ", ["ъ"] = "ʔ", ["ы"] = "ɨ", ["ь"] = "ʲ", ["э"] = "e", ["ю"] = "ju", 
	["я"] = "ja", ["ӏ"] = "ʕ", ["е̄"] = "eː", ["а̄"] = "aː", ["о̄"] = "oː", ["о̄"] = "oː", ["̄"] = "ː",
}

local scripts_IPA_double = {
	["гӏ"] = "ʁ", ["кх"] = "q͡x", ["къ"] = "q͡xʼ", ["кӏ"] = "kʼ", ["пӏ"] = "pʼ", ["тӏ"] = "tʼ", ["хь"] = "ħ", 
	["хӏ"] = "h", ["цӏ"] = "t͡sʼ", ["чӏ"] = "t͡ʃʼ", ["тт"] = "tː", ["пп"] = "pː", ["кк"] = "kː", ["сс"] = "sː", 
	["ий"] = "iː", ["ув"] = "uː", ["уо"] = "u̯o", ["ӯо"] = "uːo̯", ["ие"] = "i̯e", ["ӣе"] = "iːe̯", ["аь"] = "æ",
}

local scripts_IPA_triple = {
	["ккх"] = "q͡xː", ["рхӏ"] = "r̥", ["уьй"] = "yː",
}

local scripts_IPA_diphthongs = {
	["эв"] = "eu̯", ["ов"] = "ou̯", ["ой"] = "oi̯", ["ай"] = "ai̯",
}

function export.to_IPA(word)
    word = mw.ustring.lower(word)
    
    for pat, repl in pairs(scripts_IPA_triple) do
        word = mw.ustring.gsub(word, pat, repl)
    end
    
    for pat, repl in pairs(scripts_IPA_double) do
        word = mw.ustring.gsub(word, pat, repl)
    end
    
    for pat, repl in pairs(scripts_IPA_diphthongs) do
        word = mw.ustring.gsub(word, pat, repl)
    end

    local consonants = "[бвгджзкпстфхцчшщлмнр]"
    word = mw.ustring.gsub(word, "о̄(" .. consonants .. consonants .. ")", function(post)
        return "ɔ̯a" .. post
    end)
    
    word = "ˈ" .. word
    
    word = mw.ustring.gsub(word, ".", function(char)
        return scripts_IPA_single[char] or char
    end)
    
    return "/" .. word .. "/"
end

function export.pronunciation(frame)
    local args = frame:getParent().args
    local word = args["head"] or args[1] or mw.title.getCurrentTitle().text
    
    local ipa = export.to_IPA(word)
    
    local items = { { pron = ipa, note = nil } }
    return m_IPA.format_IPA_full { lang = lang, items = items }
end

return export