# ~*~ coding: utf-8 import random, string from zope.i18n import translate as ZopeTranslate from zope.i18n.interfaces import IUserPreferredLanguages from config import DEFAULT_LANGUAGE def getLanguage(req): prefs = IUserPreferredLanguages(req).getPreferredLanguages() lang = DEFAULT_LANGUAGE if len(prefs) > 0: lang = prefs[0] return lang def generateString(length=4): return ''.join([ random.choice(string.ascii_lowercase) for x in range(length)] ) def _genPwd(): passwd = generateString() return passwd + \ str(int(random.random()*10)) + \ str(int(random.random()*10)) + \ str(int(random.random()*10)) def translate(ctx, msgid, lang=None, domain="mdportal"): """ translate """ return ZopeTranslate(msgid, domain, target_language=lang)