Change this to def en_to_es(self):
and then include self
from the point where you call it.
Project library scripts have no scope of their own, and generally have no context (not quite true). If a variable is passed into an event, and you want it within something you call, pass it inward.