Jump to content

Module:ATC code to template name: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
more efficient?
break wikis
Line 1: Line 1:
-- this module provides a lookup from ATC codes to their associated navbox templates --
-- this module provides a lookup from ATC codes to their associated navbox templates --
local data = mw.loadData("Module:ATC code to template name/data")
local data = mw.loadData("Module:ATC code to template name/data")
local lookuptable = data.lookuptable
p = {}
p = {}


function p.translate(frame)
function translate(frame)
local input = frame.args[1]
local name = frame.args[1]
for k,v in pairs(lookuptable) do
for _, v in pairs(data) do
if v.code == input then
if v.code == name then
p.nameoftemplate = v.template
if v.template then
return frame:expandTemplate{ title = v.template }
if ( p.nameoftemplate == 42 ) then
p.out = 1
else
error("ATC code not specific enough - please use one further character (example: instead of M01, use M01A)")
error("ATC code not specific enough - please use one further character (example: instead of M01, use M01A)")
end
return
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
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
error("Invalid ATC code (or the ATC code does not have a template matched to it)")
return
end
end



Revision as of 04:50, 2 June 2021

-- this module provides a lookup from ATC codes to their associated navbox templates --
local data = mw.loadData("Module:ATC code to template name/data")
p = {}

function translate(frame)
	local name = frame.args[1]
	for _, v in pairs(data) do
		if v.code == name then
			if v.template then
				return frame:expandTemplate{ title = v.template }
			else
				error("ATC code not specific enough - please use one further character (example: instead of M01, use M01A)")
				return
			end
		end
	end
    error("Invalid ATC code (or the ATC code does not have a template matched to it)")
	return
end

return p