模組:Mt-IPA

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


local export = {}

local lang = require("Module:languages").getByCode("mt")
local m_IPA = require("Module:IPA")
local m_array = require("Module:array")
local m_table = require("Module:table")
local U = mw.ustring.char
local rsplit = mw.text.split

local vowels = "auɛiɪ"
local vowel = "[" .. vowels .. "]"
local stress_mark = U(0x02C8)

local function generate_ipa_transcription_object(terms, label)
	if #terms == 0 then
		return
	end

	local results =
		m_array(terms):map(
		function(term, _)
			return {pron = "/" .. term .. "/"}
		end
	)
	results[#terms].qualifiers = {label}

	mw.logObject(results)
	return results
end

function export.show(frame)
	local args =
		require "Module:parameters".process(
		frame:getParent().args,
		{
			[1] = {},
			[2] = {},
			[3] = {}
		}
	)

	local tr_modern, tr_archaic, tr_rural
	local results_modern, results_archaic, results_rural

	if args[1] ~= nil then
		tr_modern = rsplit(args[1], ",")
		results_modern = generate_ipa_transcription_object(tr_modern)
	end

	if args[2] ~= nil then
		tr_archaic = rsplit(args[2], ",")
		results_archaic = generate_ipa_transcription_object(tr_archaic, "archaic")
	end

	if args[3] ~= nil then
		tr_rural = rsplit(args[3], ",")	
		results_rural = generate_ipa_transcription_object(tr_rural, "archaic, rural")
	end

	if args[2] == nil then
		return "*" .. m_IPA.format_IPA_full(lang, results_modern)
	elseif args[3] == nil then
		return "*" .. m_IPA.format_IPA_full(lang, results_modern) .. "\n*" .. m_IPA.format_IPA_full(lang, results_archaic)
	else
		return "*" ..
			m_IPA.format_IPA_full(lang, results_modern) ..
				"\n**" .. m_IPA.format_IPA_full(lang, results_archaic) .. "\n**" .. m_IPA.format_IPA_full(lang, results_rural)
	end
end

return export