Difference between revisions of "Module:IPA symbol"

From Lojban
Jump to navigation Jump to search
(Updating to match new version of source page)
m (1 revision)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{languages}}'''.i la .lojban. zo'u la'a xamgu traji ke logji bangu'''
+
local p, __output, args, data = {}, {}, {}, mw.loadData("Module:IPA symbol/data")
 +
local id, output
  
.i fi'i vitke be le .uitki pe la .lojban.
+
__output.name = function() return data.correspondences[id]["name"] end
 +
__output.wikipage = function() return data.correspondences[id]["wikipage"] end
 +
__output.soundfile = function() return data.correspondences[id]["soundfile"] end
 +
__output.type = function() return data.correspondences[id]["type"] end
 +
 
 +
local function html_error(message)
 +
  if args.custom_error then
 +
    return args.custom_error
 +
  else
 +
    return mw.ustring.format(
 +
      '<strong class="error">Error using {{[[Template:IPA symbol|IPA symbol]]}}: %s%s</strong>'
 +
      ,message
 +
      ,mw.title.getCurrentTitle().isContentPage and ("[[Category:International Phonetic Alphabet pages needing attention|" .. (args[1] or "") .. "]]") or ""
 +
    )
 +
  end
 +
end
 +
 
 +
function p.main(frame)
 +
  -- all input is trimmed; accepted parameters are:
 +
  --  name              description
 +
  --  ====              ===========
 +
  --  (1)              the input
 +
  --  output            the output, one of: input; name; wikipage; soundfile; type
 +
  --  custom_output    overwrite the output when input is empty
 +
  --  custom_error      overwrite the error message
 +
  for k, v in pairs(frame.args) do
 +
    args[k] = v and mw.text.trim(v)
 +
  end
 +
 
 +
  if not args[1] or args[1] == "" then return args.custom_output or "" end
 +
 
 +
  id = data.symbols[args[1]]
 +
  if not id then return html_error('"' .. args[1] .. '" not found in list') end
 +
 
 +
  return  __output[args.output] and __output[args.output]() or html_error("No such output option")
 +
end
 +
 
 +
return p

Latest revision as of 11:51, 1 March 2014

local p, __output, args, data = {}, {}, {}, mw.loadData("Module:IPA symbol/data") local id, output

__output.name = function() return data.correspondences[id]["name"] end __output.wikipage = function() return data.correspondences[id]["wikipage"] end __output.soundfile = function() return data.correspondences[id]["soundfile"] end __output.type = function() return data.correspondences[id]["type"] end

local function html_error(message)

 if args.custom_error then
   return args.custom_error
 else
   return mw.ustring.format(
     'Error using {{IPA symbol}}: %s%s'
     ,message
     ,mw.title.getCurrentTitle().isContentPage and ("") or ""
    )
 end

end

function p.main(frame)

 -- all input is trimmed; accepted parameters are:
 --   name              description
 --   ====              ===========
 --   (1)               the input
 --   output            the output, one of: input; name; wikipage; soundfile; type
 --   custom_output     overwrite the output when input is empty
 --   custom_error      overwrite the error message
 for k, v in pairs(frame.args) do
   args[k] = v and mw.text.trim(v)
 end
 if not args[1] or args[1] == "" then return args.custom_output or "" end
 id = data.symbols[args[1]]
 if not id then return html_error('"' .. args[1] .. '" not found in list') end
 return  __output[args.output] and __output[args.output]() or html_error("No such output option")

end

return p