Jump to content

Module:aa-IPA

Long Wiktionary

Documentation for this module may be created at Module:aa-IPA/doc

local export = {} 

local m_IPA = require("Module:IPA")
local m_a = require("Module:accent qualifier")
local lang = require("Module:languages").getByCode("aa")
local s = mw.ustring.gsub
local title = mw.title.getCurrentTitle().text
local C = "[bcdfghjklmnpqrstwxyzʃ]"
local c = {
	{"sh", "ʃ"},
	{"(" .. C .. "?)á", "ˈ%1a"},
	{"(" .. C .. "?)é", "ˈ%1e"},
	{"(" .. C .. "?)í", "ˈ%1i"},
	{"(" .. C .. "?)ó", "ˈ%1o"},
	{"(" .. C .. "?)ú", "ˈ%1u"},
	{"(" .. C .. "?)à", "ˌ%1a"},
	{"(" .. C .. "?)è", "ˌ%1e"},
	{"(" .. C .. "?)ì", "ˌ%1i"},
	{"(" .. C .. "?)ò", "ˌ%1o"},
	{"(" .. C .. "?)ù", "ˌ%1u"},
	{"(.)%1", "%1ː"},
	{"r", "ɾ"},
	{"a", "ʌ"},
	{"ɾˈɾ", "rˈr"},
	{"ʌː", "aː"},
	{"ɾː", "rː"},
	{"c", "ħ"}, 
	{"g", "ɡ"},
	{"j", "d͡ʒ"},
	{"q", "ʕ"},
	{"x", "ɖ"},
	{"y", "j"},
	{"([ktp])m", "%1ʰm"}
} 

function export.pronunciation_phonemic(word)
	word = mw.ustring.lower(word)
	for a = 1, #c do
		word = s(word, c[a][1], c[a][2])
	end
	return word
end

function export.syllabify(term) --split for hyphenation
	local H, i = {}, 0
 	for a in string.gmatch(s(term, "([aeiou]" .. C .. "?)(" .. C .. ")%f[aeiou]", "%1.%2"), "[^%.-/]+") do
 		i = i+1
 		H[i] = a
 	end
 	return H
end

function export.show(frame)
	local args = frame:getParent().args
	local p, results, results_SA = {}, {}, {}
	if not args[1] or (args[1] == "") then
		error("Please put the word as the first positional parameter!")
	else
		for index, item in ipairs(args) do
			table.insert(p, (item ~= "") and item or nil)
		end
	end
	local separate_SA = false --default
	for _, word in ipairs(p) do
		word = export.pronunciation_phonemic(word)
		table.insert(results, {pron = "/" .. word .. "/"})
		table.insert(results_SA, {pron = "/" .. s(s(word, "j(ˈ?)s", "j%1ʃ"), "si", "ʃi") .. "/"})
		if word ~= s(s(word, "j(ˈ?)s", "j%1ʃ"), "si", "ʃi") then --different Southern Afar pronunciation
			separate_SA = true
		end
	end

	local H = ""
	if mw.ustring.match(title, "^[^%-].+[^%-]$") then
		H = export.syllabify(title)
		table.insert(H, 1, "aa") -- language code argument, ie. MOD:hyphenation format, next L
 		H = "\n* " .. require("Module:hyphenation").hyphenate(H)
	end

	if separate_SA then --Northern & Southern
		return "* " .. m_a.show({"Northern Afar"}) .. " " .. m_IPA.format_IPA_full(lang, results) .. "\n* " .. m_a.show({"Southern Afar"}) .. " " .. m_IPA.format_IPA_full(lang, results_SA) .. H
	else --unified
		return "* " .. m_IPA.format_IPA_full(lang, results) .. H
	end

end 

return export