Այս մոդուլն իրականացնում է {{haw-IPA}} ձևանմուշը: Այն կարող էր ընդլայնվել՝ հնարավորություն տալով բազմալեզու տառագրումների:


local export = {}

local phonetic_chars_map = {
	["a"] = "ɐ", ["ā"] = "aː", ["e"] = "e", ["ē"] = "eː",
	["i"] = "i", ["ī"] = "iː", ["o"] = "o", ["ō"] = "oː",
	["u"] = "u", ["ū"] = "uː", ["ʻ"] = "ʔ", ["z"] = "k",
	["h"] = "h", ["k"] = "k", ["l"] = "l", ["m"] = "m",
	["n"] = "n", ["p"] = "p", ["w"] = "ʋ", ["t"] = "k",
	["r"] = "l", ["s"] = "k", ["d"] = "k", ["b"] = "p",
	["c"] = "k", ["f"] = "p", ["g"] = "k", ["v"] = "ʋ"
}

function export.phonetic(word)
	if type(word) == "table" then
		word = word.args[1] or word:getParent().args[1]
	end
	if not word or (word == "") then
		error("Please insert a word as the first parameter.")
	end
	word = mw.ustring.lower(word)

	local phonetic = word

	phonetic = mw.ustring.gsub(phonetic, '.', phonetic_chars_map)

	-- short diphthongs
	phonetic = mw.ustring.gsub(phonetic, "iu", "ju")
	phonetic = mw.ustring.gsub(phonetic, "ou", "ou̯")
	phonetic = mw.ustring.gsub(phonetic, "oi", "ωi")
	phonetic = mw.ustring.gsub(phonetic, "eu", "eu̯")
	phonetic = mw.ustring.gsub(phonetic, "ei", "ei̯")
	phonetic = mw.ustring.gsub(phonetic, "ɐu", "ɐu̯")
	phonetic = mw.ustring.gsub(phonetic, "ɐi", "ɐi̯")
	phonetic = mw.ustring.gsub(phonetic, "ɐo", "ɐo̯")
	phonetic = mw.ustring.gsub(phonetic, "ɐe", "ɐe̯")
	-- long diphthongs
	phonetic = mw.ustring.gsub(phonetic, "oːu", "oːu̯")
	phonetic = mw.ustring.gsub(phonetic, "eːi", "eːi̯")
	phonetic = mw.ustring.gsub(phonetic, "aːu", "aːu̯")
	phonetic = mw.ustring.gsub(phonetic, "aːi", "aːi̯")
	phonetic = mw.ustring.gsub(phonetic, "aːo", "aːo̯")
	phonetic = mw.ustring.gsub(phonetic, "aːe", "aːe̯")
	phonetic = mw.ustring.gsub(phonetic, "̯ː", "ː")
	-- allophony of /k/
	phonetic = mw.ustring.gsub(phonetic, "k([ij])", "t%1")
	-- /j/, /w/
	phonetic = mw.ustring.gsub(phonetic, "([ie][̯]?[ː]?)([aɐo])", "%1j%2")
	phonetic = mw.ustring.gsub(phonetic, "([ie][̯]?[ː]?)u([^̯])", "%1ju%2")
	phonetic = mw.ustring.gsub(phonetic, "([ou][̯]?[ː]?)([aɐie])", "%1w%2")
	-- stress, allophony of /ɐ/, /e/
	phonetic = mw.ustring.gsub(phonetic, "ju$", "ˈju")
	phonetic = mw.ustring.gsub(phonetic, "ωi$", "ˈωi")
	phonetic = mw.ustring.gsub(phonetic, "([aɐeou][ː]?)([uioe]̯)$", "ˈ%1%2")
	phonetic = mw.ustring.gsub(phonetic, "([aeiou]ː)$", "ˈ%1")
	phonetic = mw.ustring.gsub(phonetic, "([aɐeiou][ː]?)([khjlmnptʋwʔ]?)([ɐeiou])$", "ˈ%1%2%3")
	phonetic = mw.ustring.gsub(phonetic, "([aɐeou][ː]?)([uioe]̯)([khjlmnptʋwʔ]?)([ɐeiou])$", "ˈ%1%2%3%4")
	phonetic = mw.ustring.gsub(phonetic, "ˈe([^ː])", "ˈɛ%1")
	phonetic = mw.ustring.gsub(phonetic, "([^ˈ])ɐ", "%1ə")
	phonetic = mw.ustring.gsub(phonetic, "^ɐ", "ə")
	phonetic = mw.ustring.gsub(phonetic, "ə([eiou]̯)", "ɐ%1")
	phonetic = mw.ustring.gsub(phonetic, "([khjlmnptʋwʔ])ˈ", "ˈ%1")
	phonetic = mw.ustring.gsub(phonetic, "([khlmnptʋwʔ])ˈj", "ˈ%1j")
	phonetic = mw.ustring.gsub(phonetic, "e([̯]?)([ˈ]?)([khjlmnptʋwʔ]?)ɛ", "ɛ%1%2%3ɛ")
	phonetic = mw.ustring.gsub(phonetic, "([ˈ]?)([khjlmnptʋwʔ]?)ɛ([khjlmnptʋwʔ]?)e", "%1%2ɛ%3ɛ")
	phonetic = mw.ustring.gsub(phonetic, "e([̯]?)([khjlmnptʋwʔ]?)ɛ", "ɛ%1%2ɛ")
	phonetic = mw.ustring.gsub(phonetic, "ɛ([khjlmnptʋwʔ]?)e", "ɛ%1ɛ")
	-- real value of fake "ω"; change "u̯" > "w", "i̯" > "j"
	phonetic = mw.ustring.gsub(phonetic, "ω", "o̯")
	phonetic = mw.ustring.gsub(phonetic, "u̯", "w")
	phonetic = mw.ustring.gsub(phonetic, "i̯", "j")
	phonetic = mw.ustring.gsub(phonetic, "e(.)ɛ", "ɛ%1ɛ")
	phonetic = mw.ustring.gsub(phonetic, "eɛ", "ɛɛ")
	return phonetic
end

function export.rapid(word)
	if type(word) == "table" then
		word = word.args[1] or word:getParent().args[1]
	end
	if not word or (word == "") then
		error("Please insert a word as the first parameter.")
	end
	word = mw.ustring.lower(word)

	local rapid = word

	rapid = mw.ustring.gsub(rapid, '.', phonetic_chars_map)

	-- short diphthongs
	rapid = mw.ustring.gsub(rapid, "iu", "ju")
	rapid = mw.ustring.gsub(rapid, "ou", "ou̯")
	rapid = mw.ustring.gsub(rapid, "oi", "ωi")
	rapid = mw.ustring.gsub(rapid, "eu", "eu̯")
	rapid = mw.ustring.gsub(rapid, "ei", "ei̯")
	rapid = mw.ustring.gsub(rapid, "ɐu", "ɐu̯")
	rapid = mw.ustring.gsub(rapid, "ɐi", "ɐi̯")
	rapid = mw.ustring.gsub(rapid, "ɐo", "ɐo̯")
	rapid = mw.ustring.gsub(rapid, "ɐe", "ɐe̯")
	-- long diphthongs
	rapid = mw.ustring.gsub(rapid, "oːu", "oːu̯")
	rapid = mw.ustring.gsub(rapid, "eːi", "eːi̯")
	rapid = mw.ustring.gsub(rapid, "aːu", "aːu̯")
	rapid = mw.ustring.gsub(rapid, "aːi", "aːi̯")
	rapid = mw.ustring.gsub(rapid, "aːo", "aːo̯")
	rapid = mw.ustring.gsub(rapid, "aːe", "aːe̯")
	rapid = mw.ustring.gsub(rapid, "̯ː", "ː")
	-- allophony of /k/
	rapid = mw.ustring.gsub(rapid, "k([ij])", "t%1")
	-- /j/, /w/
	rapid = mw.ustring.gsub(rapid, "([ie][̯]?[ː]?)([aɐo])", "%1j%2")
	rapid = mw.ustring.gsub(rapid, "([ie][̯]?[ː]?)u([^̯])", "%1ju%2")
	rapid = mw.ustring.gsub(rapid, "([ou][̯]?[ː]?)([aɐie])", "%1w%2")
	-- stress, allophony of /ɐ/, /e/
	rapid = mw.ustring.gsub(rapid, "ju$", "ˈju")
	rapid = mw.ustring.gsub(rapid, "ωi$", "ˈωi")
	rapid = mw.ustring.gsub(rapid, "([aɐeou][ː]?)([uioe]̯)$", "ˈ%1%2")
	rapid = mw.ustring.gsub(rapid, "([aeiou]ː)$", "ˈ%1")
	rapid = mw.ustring.gsub(rapid, "([aɐeiou][ː]?)([khjlmnptʋwʔ]?)([ɐeiou])$", "ˈ%1%2%3")
	rapid = mw.ustring.gsub(rapid, "([aɐeou][ː]?)([uioe]̯)([khjlmnptʋwʔ]?)([ɐeiou])$", "ˈ%1%2%3%4")
	rapid = mw.ustring.gsub(rapid, "ˈe([^ː])", "ˈɛ%1")
	rapid = mw.ustring.gsub(rapid, "([^ˈ])ɐ", "%1ə")
	rapid = mw.ustring.gsub(rapid, "^ɐ", "ə")
	rapid = mw.ustring.gsub(rapid, "ə([eiou]̯)", "ɐ%1")
	rapid = mw.ustring.gsub(rapid, "([khjlmnptʋwʔ])ˈ", "ˈ%1")
	rapid = mw.ustring.gsub(rapid, "([khlmnptʋwʔ])ˈj", "ˈ%1j")
	rapid = mw.ustring.gsub(rapid, "e([̯]?)([ˈ]?)([khjlmnptʋwʔ]?)ɛ", "ɛ%1%2%3ɛ")
	rapid = mw.ustring.gsub(rapid, "([ˈ]?)([khjlmnptʋwʔ]?)ɛ([khjlmnptʋwʔ]?)e", "%1%2ɛ%3ɛ")
	rapid = mw.ustring.gsub(rapid, "e([̯]?)([khjlmnptʋwʔ]?)ɛ", "ɛ%1%2ɛ")
	rapid = mw.ustring.gsub(rapid, "ɛ([khjlmnptʋwʔ]?)e", "ɛ%1ɛ")
	-- real value of fake "ω"; change "u̯" > "w", "i̯" > "j"
	rapid = mw.ustring.gsub(rapid, "ω", "o̯")
	rapid = mw.ustring.gsub(rapid, "u̯", "w")
	rapid = mw.ustring.gsub(rapid, "i̯", "j")
	rapid = mw.ustring.gsub(rapid, "e(.)ɛ", "ɛ%1ɛ")
	rapid = mw.ustring.gsub(rapid, "eɛ", "ɛɛ")
	-- fast speech value of "ɐ"
	rapid = mw.ustring.gsub(rapid, "ɐw", "ɔw")
	rapid = mw.ustring.gsub(rapid, "ɐj", "ɛj")
	return rapid
end

function export.phonemic(word)
	if type(word) == "table" then
		word = word.args[1] or word:getParent().args[1]
	end
	if not word or (word == "") then
		error("Please insert a word as the first parameter.")
	end
	word = mw.ustring.lower(word)

	local phonemic = word

	phonemic = mw.ustring.gsub(phonemic, '.', phonetic_chars_map)
	phonemic = mw.ustring.gsub(phonemic, "ɐ", "a")
	phonemic = mw.ustring.gsub(phonemic, "ʋ", "v")
	-- short diphthongs
	phonemic = mw.ustring.gsub(phonemic, "iu", "ju")
	phonemic = mw.ustring.gsub(phonemic, "ou", "ou̯")
	phonemic = mw.ustring.gsub(phonemic, "oi", "ωi")
	phonemic = mw.ustring.gsub(phonemic, "eu", "eu̯")
	phonemic = mw.ustring.gsub(phonemic, "ei", "ei̯")
	phonemic = mw.ustring.gsub(phonemic, "au", "au̯")
	phonemic = mw.ustring.gsub(phonemic, "ai", "ai̯")
	phonemic = mw.ustring.gsub(phonemic, "ao", "ao̯")
	phonemic = mw.ustring.gsub(phonemic, "ae", "ae̯")
	-- long diphthongs
	phonemic = mw.ustring.gsub(phonemic, "oːu", "oːu̯")
	phonemic = mw.ustring.gsub(phonemic, "eːi", "eːi̯")
	phonemic = mw.ustring.gsub(phonemic, "aːu", "aːu̯")
	phonemic = mw.ustring.gsub(phonemic, "aːi", "aːi̯")
	phonemic = mw.ustring.gsub(phonemic, "aːo", "aːo̯")
	phonemic = mw.ustring.gsub(phonemic, "aːe", "aːe̯")
	phonemic = mw.ustring.gsub(phonemic, "̯ː", "ː")
	-- stress
	phonemic = mw.ustring.gsub(phonemic, "ju$", "ˈju")
	phonemic = mw.ustring.gsub(phonemic, "ωi$", "ˈωi")
	phonemic = mw.ustring.gsub(phonemic, "([aeou][ː]?)([uioe]̯)$", "ˈ%1%2")
	phonemic = mw.ustring.gsub(phonemic, "([aeiou]ː)$", "ˈ%1")
	phonemic = mw.ustring.gsub(phonemic, "([aeiou][ː]?)([khjlmnpvʔ]?)([aeiou])$", "ˈ%1%2%3")
	phonemic = mw.ustring.gsub(phonemic, "([aeou][ː]?)([uioe]̯)([khjlmnpvʔ]?)([aeiou])$", "ˈ%1%2%3%4")
	phonemic = mw.ustring.gsub(phonemic, "([khjlmnpvʔ])ˈ", "ˈ%1")
	phonemic = mw.ustring.gsub(phonemic, "([khlmnpvʔ])ˈj", "ˈ%1j")
	-- syllables
	phonemic = mw.ustring.gsub(phonemic, "aː([^eiuo])", "aː·%1")
	phonemic = mw.ustring.gsub(phonemic, "aː([eiuo]ː)", "aː·%1")
	phonemic = mw.ustring.gsub(phonemic, "oː([^u])", "oː·%1")
	phonemic = mw.ustring.gsub(phonemic, "eː([^i])", "eː·%1")
	phonemic = mw.ustring.gsub(phonemic, "oːuː", "oː·uː")
	phonemic = mw.ustring.gsub(phonemic, "eːiː", "eː·iː")
	phonemic = mw.ustring.gsub(phonemic, "([iu])ː", "%1ː·")
	phonemic = mw.ustring.gsub(phonemic, "̯", "̯·")
	phonemic = mw.ustring.gsub(phonemic, "([aeiou])([khjlmnpvʔaeiouω])([^̯])", "%1·%2%3")
	phonemic = mw.ustring.gsub(phonemic, "([aeiou])([khjlmnpvʔaeiouω])([^̯])", "%1·%2%3")
	phonemic = mw.ustring.gsub(phonemic, "([aeiou])([aeiou])$", "%1·%2")
	phonemic = mw.ustring.gsub(phonemic, "·ˈ", "ˈ")
	phonemic = mw.ustring.gsub(phonemic, "· ", " ")
	phonemic = mw.ustring.gsub(phonemic, "·$", "")
	phonemic = mw.ustring.gsub(phonemic, "·", ".")
	-- real value of fake "ω"; change "u̯" > "w", "i̯" > "j"
	phonemic = mw.ustring.gsub(phonemic, "ω", "o̯")
	phonemic = mw.ustring.gsub(phonemic, "u̯", "w")
	phonemic = mw.ustring.gsub(phonemic, "i̯", "j")
	return phonemic
end

return export