Module:IPA/templates

local export = {}

local m_IPA = require("Module:IPA")

local U = mw.ustring.char
local syllabic = U(0x0329)

local function track(IPA, langObject, langCode, symbols, category)
	if langObject and langObject:getCode() == langCode then
		if type(symbols) == "string" then
			if  mw.ustring.find(IPA, symbols) then
				require("Module:debug").track("IPA/" .. category)
			end
		elseif type(symbols) == "table" then
			for _, symbol in pairs(symbols) do
				if mw.ustring.find(IPA, symbol) then
					require("Module:debug").track("IPA/" .. category)
				end
			end
		end
	end
end

-- Used for [[Template:IPA]].
function export.IPA(frame)
	local params = {
		[1] = {list = true, allow_holes = true},
		["n"] = {list = true, allow_holes = true},
		["qual"] = {list = true, allow_holes = true},
		["lang"] = {required = false, default = ""},
	}
	
	local err = nil
	local args = require("Module:parameters").process(frame.getParent and frame:getParent().args or frame, params)
	local lang = mw.title.getCurrentTitle().nsText == "Template" and "en" or args["lang"]
	lang = require("Module:languages").getByCode(lang)
	
	if not lang then
		if args["lang"] == "" then
			err = "No language code specified.[[Category:Language code missing/IPA]]"
		else
			err = "The language code '" .. args["lang"] .. "' is not valid.[[Category:Language code invalid/IPA]]"
		end
	end
	
	-- Temporary test to see which Finnish entries use {{IPA}} rather than {{fi-IPA}}
	if lang and (lang:getCode() == "ca" or lang:getCode() == "fi") then
		require("Module:debug").track("IPA/" .. lang:getCode())
	end
	
	local items = {}
	
	for i = 1, math.max(args[1].maxindex, args["n"].maxindex) do
		local pron = args[1][i]
		local note = args["n"][i]
		local qual = args["qual"][i]
		
		-- [[Special:WhatLinksHere/Template:tracking/IPA/ambig]]
		track(pron, lang, "en", "iə", "ambig")
		
		-- [[Special:WhatLinksHere/Template:tracking/IPA/cs/syllabic-consonant]]
		track(pron, lang, "cs", "[mnrl]" .. syllabic, "cs/syllabic-consonant")
		
		-- [[Special:WhatLinksHere/Template:tracking/IPA/eeoo]]
		track(pron, lang, "en", { "ɪi", "ʊu", "ɪj", "ʊw" }, "eeoo")
		
		-- [[Special:WhatLinksHere/Template:tracking/IPA/Pashto]]
		track(pron, lang, "ps", "ɤ", "Pashto")
		
		--[=[	[[Special:WhatLinksHere/Template:tracking/IPA/fa/glottal-stop]]
				Persian apparently does not have a glottal stop phoneme.		]=]
		track(pron, lang, "fa", "ʔ", "fa/glottal-stop")
		
		if pron or note or qual then
			table.insert(items, {pron = pron, note = note, qualifiers = {qual}})
		end
	end
	
	return m_IPA.format_IPA_full(lang, items, err)
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 params = {
		[1] = { list = true, allow_holes = true },
		["n"] = { list = true, allow_holes = true },
		["qual"] = { list = true, allow_holes = true },
		["lang"] = { required = true },
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	pronunciations, notes, qualifiers, lang = args[1], args["n"], args["qual"], args["lang"]
	
	local output = {}
	table.insert(output, "{{IPA")
	
	for i = 1, math.max(pronunciations.maxindex, notes.maxindex, qualifiers.maxindex) do
		if pronunciations[i] then
			table.insert(output, "|"..m_IPA.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
	
	if lang then
		table.insert(output, "|lang="..lang.."}}")
	end
	
	return table.concat(output)
end

-- Used by [[Template:Wt/sco/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)
	
	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_IPA.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 params = {
		[1] = { required = true, list = true, allow_holes = true },
		["lang"] = { required = true },
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	pronunciations, lang = args[1], args["lang"]
	
	local output =  {}
	table.insert(output, "{{rhymes")
	
	for i = 1, pronunciations.maxindex do
		if pronunciations[i] then
			table.insert(output, "|"..m_IPA.XSAMPA_to_IPA(pronunciations[i]))
		end
	end
	
	if lang then
		table.insert(output, "|lang="..lang)
	end
	
	table.insert(output, "}}")
	
	return table.concat(output)
end

return export

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.