Module:User:Thadh/et-IPA

local export = {}

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

local A = mw.ustring.char(0x002A) 		-- halflength marker (asterisk) local C = "[mnptkvfsʃhlrjʒz]"			-- consonants local D = mw.ustring.char(0x0308)		-- centralisation marker (diaeresis) local L = "[ˑː]" 						-- length markers local R = mw.ustring.char(0x0325)		-- voicelessness marker (ring below) local S = mw.ustring.char(0x032F) 		-- diphthong marker local T = mw.ustring.char(0x031E)		-- lowering marker (downtack) local V = "[ɑeiouæɤøy]"					-- vowels

local phon = { -- consonants ["b"]="b̥",	["d"]="d̥",	["g"]="ɡ̊", ["p"]="p", ["t"]="t", ["k"]="k", ["v"]="v",	["ž"]="ʒ", ["f"]="f",	["š"]="ʃ", ["'"]="ʲ", -- vowels ["a"]="ɑ",	["e"]="e",	["i"]="i", ["o"]="o",	["u"]="u",	["ä"]="æ", ["õ"]="ɤ",	["ö"]="ø",	["ü"]="y", }

local function phonemic(text) -- general phonology text = mw.ustring.gsub(text, '.', phon) -- long consonants text = mw.ustring.gsub(text, "([pkt])" .. A, "%1") text = mw.ustring.gsub(text, "(" .. C .. ")" .. L .. "?%1", "%1ː") text = mw.ustring.gsub(text, "(" .. C .. ")" .. L .. "?" .. A, "%1ˑ") -- palatalised long consonants text = mw.ustring.gsub(text, "(" .. C .. ")(" .. L .. ")ʲ", "%1ʲ%2") -- long vowels text = mw.ustring.gsub(text, "(" .. V .. ")%1", "%1ː") text = mw.ustring.gsub(text, "(" .. V .. ")" .. A, "%1ˑ") -- üüV text = mw.ustring.gsub(text, "y" .. L .. "(" .. V .. ")", "yij%1") -- diphthongs text = mw.ustring.gsub(text, "([ɑeiouɤ])([ɑeiou])", "%1%2" .. S) text = mw.ustring.gsub(text, "æ([eiou])", "æ%1" .. S) text = mw.ustring.gsub(text, "ø([ɑei])", "ø%1" .. S) text = mw.ustring.gsub(text, "y([ɑeio])", "y%1" .. S)	-- stress if mw.ustring.find(text, "ˈ") == nil then text = "ˈ" .. text text = mw.ustring.gsub(text, "+", "ˌ") end text = mw.ustring.gsub(text, "(" .. L .. ")" .. L, "%1") return text end

local function phonetic(text) -- palatalisation text = mw.ustring.gsub(text, "([ndtsl])%f[ij]", "%1ʲ") -- velar nasal text = mw.ustring.gsub(text, "n%f[kg]", "ŋ") -- glide insertion text = mw.ustring.gsub(text, "(" .. V .. ")i(" .. V .. ")", "%1ij%2") text = mw.ustring.gsub(text, "(" .. V .. ")u(" .. V .. ")", "%1uw%2") -- flash forward to after phonemic transcription text = phonemic(text) -- optional initial h-	text = mw.ustring.gsub(text, "^ˈh", "ˈ(h)") -- h-voicing text = mw.ustring.gsub(text, "(" .. V .. S .. "?)h(" .. V .. ")", "%1ɦ%2") -- short gemination text = mw.ustring.gsub(text, "(" .. V .. S .. "?)([ptk]ʲ?)(" .. V .. ")", "%1%2ˑ%3") text = mw.ustring.gsub(text, "([ptk]ʲ?)$", "%1ˑ") text = mw.ustring.gsub(text, "([ptk]ʲ?)([ptksfʃ])", "%1ˑ%2") text = mw.ustring.gsub(text, "([bpdtɡkshfʃzʒ]" .. R .. "?" .. L .. "?)([ptk]ʲ?)ˑ", "%1%2") -- final devoicing text = mw.ustring.gsub(text, "b̥$", "p") text = mw.ustring.gsub(text, "d̥$", "t") text = mw.ustring.gsub(text, "ɡ̊$", "k") text = mw.ustring.gsub(text, "([ths]ʲ?)([mnrvl])$", "%1ˑ%2" .. R)	-- vowel articulation text = mw.ustring.gsub(text, "e$", "e" .. T) text = mw.ustring.gsub(text, "jɑ", "jɑ" .. D) text = mw.ustring.gsub(text, "ɑj", "ɑ" .. D .. "j") text = mw.ustring.gsub(text, "ju", "ju" .. D) text = mw.ustring.gsub(text, "uj", "u" .. D .. "j") return text end

function export.IPA(frame) local emic = {} local etic = {} for _, word in ipairs(frame:getParent.args) do		table.insert(emic, word) table.insert(etic, word) end if #emic == 0 then emic = {mw.title.getCurrentTitle.text} etic = {mw.title.getCurrentTitle.text} end for key, word in ipairs(emic) do		emic[key] = phonemic(word) etic[key] = phonetic(word) end -- hardcoding this because I'm not that good at Lua if #emic <= 1 then return m_IPA.format_IPA_full { lang = lang, items = { { pron = "/" .. table.concat(emic) .. "/" },				{ pron = "[" .. table.concat(etic) .. "]" }			},		}	elseif #emic == 2 then return m_IPA.format_IPA_full { lang = lang, items = { { pron = "/" .. emic[1] .. "/" },				{ pron = "[" .. etic[1] .. "]" },				{ pron = "/" .. emic[2] .. "/" },				{ pron = "[" .. etic[2] .. "]" },			},		}	end end

return export