Module:ATC code to template name: Difference between revisions
Appearance
Content deleted Content added
break wikis |
put on p |
||
Line 3: | Line 3: | ||
p = {} |
p = {} |
||
function translate(frame) |
function p.translate(frame) |
||
local name = frame.args[1] |
local name = frame.args[1] |
||
for _, v in pairs(data) do |
for _, v in pairs(data) do |
Latest revision as of 04:52, 2 June 2021
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 = mw.loadData("Module:ATC code to template name/data")
p = {}
function p.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