Մոդուլ:IPA/templates

Վիքիբառարան-ից

Այս մոդուլն օգտագործվում է {{IPA}}, {{IPAchar}}.

Որովհետեւ {{IPA}} միշտ ներառում է լեզվի կոդ, կարող եք հետևել, երբ որոշակի սիմվոլներ կամ խորհրդանիշների հաջորդականություններ օգտագործվում են որոշակի լեզվի IPA տառերով: Սա թույլ է տալիս գտնել և ուղղել սխալ տառադարձումները: Հետևելու գործառույթը հայտնաբերված է Մոդուլ:IPA/tracking.


local m_IPA = require("Module:IPA")

local export = {}

-- Used for [[Template:IPAchar]] and [[Template:IPA]].
function export.IPA(frame)
	local args = frame:getParent().args
	
	-- Gather parameters
	local pronunciations = {}
	local notes = {}
	local i = 1
	local pron = args[i]; if pron == "" then pron = nil end
	
	while pron do
		table.insert(pronunciations, pron)
		
		local note = args['n' .. i]; if note == "" then note = nil end
		notes[#pronunciations] = note
		
		i = i + 1
		pron = args[i]; if pron == "" then pron = nil end
	end
	
	-- Format
	if #pronunciations == 0 then
		return "[[Category:Pronunciation templates without a pronunciation]]"
	else
		return m_IPA.IPA_multiple(pronunciations, notes)
	end
end

-- Used for [[Template:IPAchar]].
function export.IPAchar(frame)
	local params = {
		[1] = {list = true, allow_holes = true},
		["n"] = {list = true, allow_holes = true},
		["lang"] = {}, -- This parameter is not used and does nothing, but is allowed for futureproofing.
	}
	
	local args = require("Module:parameters").process(frame.getParent and frame:getParent().args or frame, params)
	
	local items = {}
	
	for i = 1, math.max(args[1].maxindex, args["n"].maxindex) do
		local pron = args[1][i]
		local note = args["n"][i]
		
		if pron or note then
			table.insert(items, {pron = pron, note = note})
		end
	end
	
	-- Format
	return m_IPA.format_IPA_multiple(nil, items)
end

function export.XSAMPA(frame)
	local params = {
		[1] = { required = true },
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	return m_IPA.XSAMPA_to_IPA(args[1] or "[Eg'zA:mp5=]")
end

-- Used by [[Template:X2IPA]]
function export.X2IPAtemplate(frame)
	local parent_args = frame.getParent and frame:getParent().args or frame
	local compat = parent_args["lang"]
	local offset = compat and 0 or 1

	local params = {
		[compat and "lang" or 1] = {required = true, default = "und"},
		[1 + offset] = {list = true, allow_holes = true},
		["n"] = { list = true, allow_holes = true },
		["qual"] = { list = true, allow_holes = true },
	}
	
	local args = require("Module:parameters").process(parent_args, params)
	
	local m_XSAMPA = require("Module:IPA/X-SAMPA")
	
	pronunciations, notes, qualifiers, lang = args[1 + offset], args["n"], args["qual"], args[compat and "lang" or 1]
	
	local output = {}
	table.insert(output, "{{IPA")
	
	table.insert(output, "|" .. lang)

	for i = 1, math.max(pronunciations.maxindex, notes.maxindex, qualifiers.maxindex) do
		if pronunciations[i] then
			table.insert(output, "|"..m_XSAMPA.XSAMPA_to_IPA(pronunciations[i]))
		end
		if notes[i] then
			table.insert(output, "|n"..i.."="..notes[i])
		end
		if qualifiers[i] then
			table.insert(output, "|qual"..i.."="..qualifiers[i])
		end
	end
	
	table.insert(output, "}}")

	return table.concat(output)
end

-- Used by [[Template:X2IPAchar]]
function export.X2IPAchar(frame)
	local params = {
		[1] = { list = true, allow_holes = true },
		["n"] = { list = true, allow_holes = true },
		["lang"] = { },
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local m_XSAMPA = require("Module:IPA/X-SAMPA")
	
	pronunciations, notes, lang = args[1], args["n"], args["lang"]
	
	local output = {}
	table.insert(output, "{{IPAchar")
	
	for i = 1, math.max(pronunciations.maxindex, notes.maxindex) do
		if pronunciations[i] then
			table.insert(output, "|"..m_XSAMPA.XSAMPA_to_IPA(pronunciations[i]))
		end
		if notes[i] then
			table.insert(output, "|n"..i.."="..notes[i])
		end
	end
	
	if lang then
		table.insert(output, "|lang="..lang)
	end
	
	table.insert(output, "}}")
	
	return table.concat(output)
end

-- Used by [[Template:x2rhymes]]
function export.X2rhymes(frame)
	local parent_args = frame.getParent and frame:getParent().args or frame
	local compat = parent_args["lang"]
	local offset = compat and 0 or 1

	local params = {
		[compat and "lang" or 1] = {required = true, default = "und"},
		[1 + offset] = {required = true, list = true, allow_holes = true},
	}
	
	local args = require("Module:parameters").process(parent_args, params)
	
	local m_XSAMPA = require("Module:IPA/X-SAMPA")
	
	pronunciations, lang = args[1 + offset], args[compat and "lang" or 1]
	
	local output =  {}
	table.insert(output, "{{rhymes")
	
	table.insert(output, "|" .. lang)

	for i = 1, pronunciations.maxindex do
		if pronunciations[i] then
			table.insert(output, "|"..m_XSAMPA.XSAMPA_to_IPA(pronunciations[i]))
		end
	end
	
	table.insert(output, "}}")
	
	return table.concat(output)
end

return export