Module:Unit: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
mNo edit summary
mNo edit summary
Line 9: Line 9:
if args[1] then
if args[1] then
local abbrKey = tostring(args[1])
local abbrKey = tostring(args[1])
local unitData = UnitsData["caseSensitiveUnits"][abbrKey]


if abbrKey then
if not unitData then
local unitData = UnitsData["caseSensitiveUnits"][abbrKey]
unitData = UnitsData["caseInsensitiveUnits"][abbrKey]
 
end
if not unitData then
unitData = UnitsData["caseInsensitiveUnits"][abbrKey]
end


if unitData then
if unitData then
return HTMLUtils.tagAbbr(unitData[1], unitData[2])
return HTMLUtils.tagAbbr(unitData[1], unitData[2])
else
return abbrKey
end
else
else
return string.format("ERROR: Invalid abbreviation \"%s\"!", abbrKey)
return abbrKey
end
end
else
else
return "ERROR: No unit symbol given!"
return ""
end
end
end
end


return p
return p

Revision as of 19:41, 23 February 2022

local p = {}
local Utils = require("Module:Utils")
local UnitsData = mw.loadData("Module:Sandbox/Demian/Unit/data")
local HTMLUtils = require("Module:UtilsHTML")

function p.main(frame)
	local args = Utils.normaliseArgs(frame)

	if args[1] then
		local abbrKey = tostring(args[1])
		local unitData = UnitsData["caseSensitiveUnits"][abbrKey]

		if not unitData then
			unitData = UnitsData["caseInsensitiveUnits"][abbrKey]
		end

		if unitData then
			return HTMLUtils.tagAbbr(unitData[1], unitData[2])
		else
			return abbrKey
		end
	else
		return ""
	end
end

return p