Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Nardog/8
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local data = mw.loadData('Module:Sandbox/Nardog/8t').data local p = {} local find = mw.ustring.find local gsub = mw.ustring.gsub local sub = mw.ustring.sub local trim = mw.text.trim local function reverseLook(t, s) local ret for i = 1, #s - 1 do ret = t[sub(s, i, 2)] -- Look for 2-char matches first if ret then return ret end ret = t[sub(s, i, 1)] 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() local ns = mw.title.getCurrentTitle().namespace if ns % 2 == 0 and ns ~= 2 then -- Non-talk and non-user return '[[Category:International Phonetic Alphabet pages needing attention]]' else return '' end 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 '' end -- Exit early 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, errorText) local t = returnData(s) if t then local span = mw.html.create('span'):addClass('IPA') if prefix or suffix then span:addClass('nowrap'):attr('title', 'Representation in the International Phonetic Alphabet (IPA)') end span:wikitext(string.format('%s[[%s|%s]]%s', prefix or '', t.article, displayText or s, suffix or '')) if audio then audio = require('Module:Yesno')(audio, audio) if audio == true then audio = t.audio end if audio ~= '' then audio = mw.getCurrentFrame():expandTemplate{ title = 'Template:Audio', args = { audio, 'listen', help = 'no' } } audio = ' <span class="nowrap" style="font-size:85%">(' .. audio .. ')</span>' end else audio = '' end return tostring(span) .. 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 '' end -- Exit early if args.errortext == 'blank' then args.errortext = '' end return p._link(args.symbol, args.text, args.prefix, args.suffix, args.audio, args.errortext) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Nardog/8/doc
(
edit
)