Module:ky-IPA

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Kyrgyz pronunciation module, powers {{ky-IPA}}. This is under development and may contain errors; mass deployment on entries is discouraged.

TODO[edit]

  • IMPORTANT: Iotated Ее handling
  • Stress handling
  • Initial voicing of front row K
  • Exceptional short vowels pronounced with long vowels, such as in Нарын, бардыгы

local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("ky")

local C_set = "бвгджзйклмнңпрстфхцчшщ" -- consonants
local bV_set = "аыоу"
local fV_set = "эиөү"
local iV_set = "еёюя" -- iotated vowels
local V_set = bV_set .. fV_set .. iV_set -- all vowels

local C = "[" .. C_set .. "]" -- consonants
local bV = "[" .. bV_set .. "]"
local fV = "[" .. fV_set .. "]"
local iV = "[" .. iV_set .. "]" -- iotated vowels
local V = "[" .. V_set .. "]" -- all vowels

local lowerc = {
	["А"]="а", ["Б"]="б", ["В"]="в", ["Г"]="г", ["Д"]="д", ["Е"]="е", 
	["Ё"]="ё", ["Ж"]="ж", ["З"]="з", ["И"]="и", ["Й"]="й", ["К"]="к", 
	["Л"]="л", ["М"]="м", ["Н"]="н", ["Ң"]="ң", ["О"]="о", ["Ө"]="ө", 
	["П"]="п", ["Р"]="р", ["С"]="с", ["Т"]="т", ["У"]="у", ["Ү"]="ү", 
	["Ф"]="ф", ["Х"]="х", ["Ц"]="ц", ["Ч"]="ч", ["Ш"]="ш", ["Щ"]="щ", 
	["Ъ"]="ъ", ["Ы"]="ы", ["Ь"]="ь", ["Э"]="э", ["Ю"]="ю", ["Я"]="я"
}

local phon = {
	["б"]="b", ["г"]="ɡ", ["д"]="d", ["ж"]="d͡ʒ", ["з"]="z", ["й"]="j",
	["к"]="k", ["л"]="l̴", ["м"]="m", ["н"]="n", ["ң"]="ŋ", ["п"]="p", 
	["р"]="r", ["с"]="s", ["т"]="t", ["ч"]="t͡ʃ", ["ш"]="ʂ", ["е"]="e",
	["ё"]="jo", ["ю"]="ju", ["я"]="jɑ", ["а"]="ɑ", ["ы"]="ɯ", ["о"]="o", 
	["у"]="u", ["э"]="e", ["и"]="i", ["ө"]="ø", ["ү"]="y", ["в"]="v", 
	["ф"]="f", ["х"]="x", ["ц"]="t͡s", ["ч"]="t͡ʃ", ["щ"]="ɕ", ["ь"]="ʲ"
}

function export.phonetic(text)
	text = mw.ustring.gsub(text, '.', lowerc)
	
	-- Handle iotated Е
	text = mw.ustring.gsub(text, "^е", "je")
	text = mw.ustring.gsub(text, "([ " .. V_set .. "ьъ])е", "%1je")
	
    text = mw.ustring.gsub(text, '.', phon)
    
	-- Handle к, г uvularization rules
	text = mw.ustring.gsub(text, "k[ɑɯou]", "q%1")
	text = mw.ustring.gsub(text, "ɡ[ɑɯou]", "ʁ%1")
	text = mw.ustring.gsub(text, "qk", "q")
	text = mw.ustring.gsub(text, "ʁɡ", "ʁ")
	text = mw.ustring.gsub(text, "[ɑɯou]k", "%1q")
	text = mw.ustring.gsub(text, "[ɑɯou]ɡ", "%1ʁ")
	text = mw.ustring.gsub(text, "kq", "q")
	text = mw.ustring.gsub(text, "ɡʁ", "ʁ")
	
	-- Handle ш rules
	text = mw.ustring.gsub(text, "ʂ[eiøy]", "ʃ%1")
	text = mw.ustring.gsub(text, "[eiøy]ʂ", "%1ʃ")
	text = mw.ustring.gsub(text, "ʂʃ", "ʃ")
	text = mw.ustring.gsub(text, "ʃʂ", "ʃ")

	-- Handle l rules
	text = mw.ustring.gsub(text, "l̴[eiøy]", "l%1")
	text = mw.ustring.gsub(text, "[eiøy]l̴", "%1l")
	text = mw.ustring.gsub(text, "ll̴", "l̴")
	text = mw.ustring.gsub(text, "l̴l", "l̴")
	
	-- Handle long vowels
	text = mw.ustring.gsub(text, "[ɑ]ɑ", "ɑː")
	text = mw.ustring.gsub(text, "[o]o", "oː")
	text = mw.ustring.gsub(text, "[u]u", "uː")
	text = mw.ustring.gsub(text, "[e]e", "eː")
	text = mw.ustring.gsub(text, "[ø]ø", "øː")
	text = mw.ustring.gsub(text, "[y]y", "yː")
	return text
end

function export.IPA(frame)
	local words = {}

	for _, word in ipairs(frame:getParent().args) do
		table.insert(words, word)
	end

	if #words == 0 then
		words = {mw.title.getCurrentTitle().text}
	end

	local IPA_results = {}
	
	for _, word in ipairs(words) do
		table.insert(IPA_results, { pron = "/" .. export.phonetic(word) .. "/" })
	end
	
	return m_IPA.format_IPA_full(lang, IPA_results)
end

return export