模組:Aa-IPA

維基詞典,自由的多語言詞典


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 = {
	[1] = {"sh", "ʃ"},
	[2] = {"(" .. C .. "?)á", "ˈ%1a"},
	[3] = {"(" .. C .. "?)é", "ˈ%1e"},
	[4] = {"(" .. C .. "?)í", "ˈ%1i"},
	[5] = {"(" .. C .. "?)ó", "ˈ%1o"},
	[6] = {"(" .. C .. "?)ú", "ˈ%1u"},
	[7] = {"(" .. C .. "?)à", "ˌ%1a"},
	[8] = {"(" .. C .. "?)è", "ˌ%1e"},
	[9] = {"(" .. C .. "?)ì", "ˌ%1i"},
	[10] = {"(" .. C .. "?)ò", "ˌ%1o"},
	[11] = {"(" .. C .. "?)ù", "ˌ%1u"},
	[12] = {"(.)%1", "%1ː"},
	[13] = {"r", "ɾ"},
	[14] = {"a", "ʌ"},
	[15] = {"ɾˈɾ", "rˈr"},
	[16] = {"ʌː", "aː"},
	[17] = {"ɾː", "rː"},
	[18] = {"c", "ħ"}, 
	[19] = {"g", "ɡ"},
	[20] = {"j", "d͡ʒ"},
	[21] = {"q", "ʕ"},
	[22] = {"x", "ɖ"},
	[23] = {"y", "j"},
	[24] = {"([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)
	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
	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
			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
 		H = "\n* " .. require("Module:hyphenation").hyphenate(H)
	end

	if separate_SA then
		return "* " .. m_a.show({"北部方言"}) .. " " .. m_IPA.format_IPA_full(lang, results) .. "\n* " .. m_a.show({"南部方言"}) .. " " .. m_IPA.format_IPA_full(lang, results_SA) .. H
	else
		return "* " .. m_IPA.format_IPA_full(lang, results) .. H
	end

end 

return export