-- Demo of a module that takes a QID from a Wikidata unit entry-- and returns the code for that unit which can accept-- can also return the name of the unit, if required
local p = require('Module:Sandbox/RexxS/Units')
p.sing = function(frame) local QID = mw.text.trim(frame.args[1] or "") if QID and unitByQid[QID] then return unitByQid[QID].singular else return "singular not known" endend
p.plur = function(frame) local QID = mw.text.trim(frame.args[1] or "") if QID and unitByQid[QID] then if unitByQid[QID].plural then return unitByQid[QID].plural elseif unitByQid[QID].singular then -- no plural, but a singular exists, so add 's': return unitByQid[QID].singular .. 's' end else return "plural not known" endend
p.conv = function(frame) local QID = mw.text.trim(frame.args[1] or "") if QID and unitByQid[QID] then return unitByQid[QID].convertcode else return "convert code not known" endend
return p