def tmpl_globals(): """Create and return a dictionary of global variables for all templates. This function was adapted from :func:`pylons.templating.pylons_globals` to better suite our needs. In particular we inject our own gettext functions and get a performance boost from following the translator SOP once here instead of on every gettext call. """ conf = config._current_obj() g = conf['pylons.app_globals'] c = tmpl_context._current_obj() t = translator._current_obj() return { 'config': conf, 'c': c, 'tmpl_context': c, 'g': g, 'app_globals': g, 'h': conf['pylons.h'], 'request': request._current_obj(), 'response': response, # don't eval the SOP because this is rarely used 'translator': t, 'ngettext': t.ngettext, 'ungettext': t.ungettext, # compat with standard pylons_globals() '_': t.gettext, 'N_': N_, 'XML': XML, }
def tmpl_globals(): """Create and return a dictionary of global variables for all templates. This function was adapted from :func:`pylons.templating.pylons_globals` to better suite our needs. In particular we inject our own gettext functions and get a performance boost from following the translator SOP once here instead of on every gettext call. """ conf = config._current_obj() g = conf['pylons.app_globals'] c = tmpl_context._current_obj() t = translator._current_obj() req = request._current_obj() return { 'config': conf, 'c': c, 'tmpl_context': c, 'g': g, 'app_globals': g, 'h': conf['pylons.h'], 'request': req, 'settings': req.settings, 'response': response, # don't eval the SOP because this is rarely used 'translator': t, 'ngettext': t.ngettext, 'ungettext': t.ungettext, # compat with standard pylons_globals() '_': t.gettext, 'N_': N_, 'XML': XML, }
def tmpl_globals(): """Create and return a dictionary of global variables for all templates. This function was adapted from :func:`pylons.templating.pylons_globals` to better suite our needs. In particular we inject our own gettext functions and get a performance boost from following the translator SOP once here instead of on every gettext call. """ conf = config._current_obj() g = conf["pylons.app_globals"] c = tmpl_context._current_obj() t = translator._current_obj() req = request._current_obj() return { "config": conf, "c": c, "tmpl_context": c, "g": g, "app_globals": g, "h": conf["pylons.h"], "request": req, "settings": req.settings, "response": response, # don't eval the SOP because this is rarely used "translator": t, "ngettext": t.ngettext, "ungettext": t.ungettext, # compat with standard pylons_globals() "_": t.gettext, "N_": N_, "XML": XML, }
def gettext(msgid, domain=None): """Get the translated string for this msgid in the given domain. :type msgid: ``str`` :param msgid: A byte string to retrieve translations for. :type domain: ``str`` :param domain: An optional domain to use, if not 'mediacore'. :rtype: ``unicode`` :returns: The translated string, or the original msgid if no translation was found. """ translator_obj = translator._current_obj() if not isinstance(translator_obj, Translator) and config['debug']: log.warn('_, ugettext, or gettext called with msgid "%s" before '\ 'pylons.translator has been replaced with our custom version.'\ % msgid) return translator_obj.gettext(msgid) return translator_obj.gettext(msgid, domain)
def gettext(msgid, domain=None): """Get the translated string for this msgid in the given domain. :type msgid: ``str`` :param msgid: A byte string to retrieve translations for. :type domain: ``str`` :param domain: An optional domain to use, if not 'mediadrop'. :rtype: ``unicode`` :returns: The translated string, or the original msgid if no translation was found. """ translator_obj = translator._current_obj() if not isinstance(translator_obj, Translator): if config['debug']: log.warn('_, ugettext, or gettext called with msgid "%s" before '\ 'pylons.translator has been replaced with our custom '\ 'version.' % msgid) return translator_obj.gettext(msgid) return translator_obj.gettext(msgid, domain)