Difference between revisions of "Module:ATC code to template name"

From blackwiki
Jump to navigation Jump to search
blackwiki>Berchanhimez
(test)
blackwiki>Berchanhimez
(test)
Line 15: Line 15:
 
}
 
}
  
function p.translate ( param )
+
function p.translate ()
 
for k,v in pairs(p.lookuptable) do
 
for k,v in pairs(p.lookuptable) do
if v.code == param then
+
if v.code == input then
 
p.out = v.template
 
p.out = v.template
 
print(p.out)
 
print(p.out)

Revision as of 07:05, 5 July 2020

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

p = {}

local frame = mw.getCurrentFrame()

local input = frame.args[1]

p.lookuptable = {
{ code="A01", template="Stomatological preparations",},
{ code="A02A", template="Antacids", },
{ code="A02B", template="Drugs for peptic ulcer and GORD", },
{ code="A03", template="Drugs for functional gastrointestinal disorders", },
{ code="A04", template="Antiemetics", },
}

function p.translate ()
	for k,v in pairs(p.lookuptable) do
		if v.code == input then
			p.out = v.template
			print(p.out)
        end
    end
    if p.out == nil then
        error("None")
    end
    return p.out
end

return p