Translates an ATC code passed as an unnamed parameter to the function "translate" into the name of the navbox template associated with that ATC code on Wikipedia.
Use:
{{#invoke:ATC code to template name|translate|X00}}
The template returned does not have the Template: prefix.
-- this module provides a lookup from ATC codes to their associated navbox templates --
local data = require("Module:ATC code to template name/data")
local lookuptable = data.lookuptable
p = {}
function p.translate(frame)
local input = frame.args[1]
for k,v in pairs(lookuptable) do
if v.code == input then
p.nameoftemplate = v.template
if ( p.nameoftemplate == 42 ) then
p.out = 1
error("ATC code not specific enough - please use one further character (example: instead of M01, use M01A)")
end
if ( p.nameoftemplate == tostring(42) ) then
p.out = 1
error("ATC code not specific enough - please use one further character (example: instead of M01, use M01A)")
end
if ( p.nameoftemplate ~= nil ) then
p.out = frame:expandTemplate{ title = p.nameoftemplate }
end
end
end
if p.out == nil then
error("Invalid ATC code (or the ATC code does not have a template matched to it)")
end
if ( p.out ~= 1 ) then
return p.out
end
end
return p