Module:IPA symbol

local data = mw.loadData('Module:IPA symbol/data').data
local p = {}

local gsub = mw.ustring.gsub
local len = mw.ustring.len
local sub = mw.ustring.sub

local function reverseLook(t, s)
	local ret
	for i = 1, len(s) - 1 do
		-- Look for 2-char matches first
		ret = t[sub(s, i, i + 1)] or t[sub(s, i, i)]
		if ret then
			return ret
		end
	end
	ret = t[sub(s, -1)] -- Last character
	if ret then
		return ret
	end
end

local function returnData(s, dataType)
	for _, v in ipairs(data.univPatterns) do
		s = gsub(s, v.pat, v.rep)
	end
	local key = s
	for _, v in ipairs(data.keyPatterns) do
		key = gsub(key, v.pat, v.rep)
	end
	local ret = data.sounds[key] or data.diacritics[key]
		or reverseLook(data.diacritics, s)
	if ret and dataType then
		if ret[dataType] then
			ret = ret[dataType]
		else
			error(string.format('Invalid data type "%s"', dataType))
		end
	end
	return ret
end

local function returnErrorCat()
	return require('Module:Category handler').main({ true }) and
		'[[Category:International Phonetic Alphabet pages needing attention]]' or
		''
end

local function returnError(s)
	return string.format(
		'<span class="error">Error using {{[[Template:IPA symbol|IPA symbol]]}}: "%s" not found in list</span>%s',
		s, returnErrorCat())
end

function p._main(s, errorText, output)
	return returnData(s, output or 'article') or errorText or returnError(s)
end

function p.main(frame)
	local args = {}
	for k, v in pairs(frame.args) do
		args[k] = v ~= '' and v
	end
	if not args.symbol then
		return '' -- Exit early
	end
	if args.errortext == 'blank' then
		args.errortext = ''
	end
	return p._main(args.symbol, args.errortext, args.output)
end

function p._link(s, displayText, prefix, suffix, audio, addSpan, errorText)
	local t = returnData(s)
	if t then
		s = string.format('%s[[:%s|%s]]%s',
			prefix or '', t.article, displayText or s, suffix or '')
		if addSpan ~= 'no' then
			local span = mw.html.create('span'):addClass('IPA'):attr('lang', 'und-Latn-fonipa')
			if prefix or suffix then
				span:addClass('nowrap'):attr('title',
					'Representation in the International Phonetic Alphabet (IPA)')
			end
			s = tostring(span:wikitext(s))
		end
		if audio then
			audio = require('Module:Yesno')(audio, audio)
			audio = audio == true and t.audio or audio
			if audio ~= '' then
				audio = ' ' .. mw.getCurrentFrame():expandTemplate{
					title = 'Template:Audio',
					args = { audio, '', help = 'no' }
				}
			end
		else
			audio = ''
		end
		return s .. audio
	 else
		return errorText or returnError(s)
	end
end

function p.link(frame)
	local args = {}
	for k, v in pairs(frame.args) do
		args[k] = v ~= '' and v
	end
	if not args.symbol then
		return '' -- Exit early
	end
	if args.errortext == 'blank' then
		args.errortext = ''
	end
	return p._link(args.symbol, args.text, args.prefix, args.suffix, args.audio,
		args.span, args.errortext)
end

return p

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.