ข้ามไปเนื้อหา

มอดูล:ug-pron

จาก วิกิพจนานุกรม พจนานุกรมเสรี

local export = {}
local gsub = mw.ustring.gsub
local lang = require("Module:languages").getByCode("ug")
local m_IPA = require("Module:IPA")

function export.pronunciation(word)
	
	--word = lang:transliterate(word)
	word = require("Module:ug-translit-Latn").tr(word, "ug", "ug-Arab")
	word = mw.ustring.lower(word) -- Cyrillic & Latin sometimes use capital letters
	
	word = gsub(word, "^([aeiouéëöü])", "ʔ%1")
	word = gsub(word, "([%s%p])([aeiouéëöü])", "%1ʔ%2")
	word = gsub(word, "([aeiouéëöü])'([aeiouéëöü])", "%1ʔ%2") -- V'V can be manually added

	word = gsub(word, "ng", "ŋ")
	word = gsub(word, "gh", "ʁ")
	word = gsub(word, "ch", "t͡ʃ")
	word = gsub(word, "zh", "ʒ")
	word = gsub(word, "sh", "ʃ")
	
	word = gsub(word, "g", "ɡ")
	word = gsub(word, "x", "χ")
	word = gsub(word, "j", "d͡ʒ")
	word = gsub(word, "y", "j")
	word = gsub(word, "a", "ɑ")
	word = gsub(word, "e", "ɛ")
	word = gsub(word, "[éë]", "e")
	word = gsub(word, "ö", "ø")
	word = gsub(word, "ü", "y")
	word = gsub(word, "['%?,;]", "") -- must be at last step

	return word
end

function export.show(frame)
	local args = frame:getParent().args
	local pagetitle = mw.title.getCurrentTitle().text

	local p, results = {}, {}

	if args[1] then
		for _, item in ipairs(args) do
			table.insert(p, (item ~= "") and item or nil)
		end
	else
		p = {pagetitle}
	end

	for _, word in ipairs(p) do
		table.insert(results, {pron = "/" .. export.pronunciation(word) .. "/"})
	end

	return "* " .. m_IPA.format_IPA_full { lang = lang, items = results }
end

return export