Move translation logic out of Mako templates