Jump to content

Module:ATC code to template name

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Elli (talk | contribs) at 04:36, 2 June 2021 (move data to submodule, simplify coding). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- 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