On Mar 13, 1:14 pm, Zhang Huangbin <[email protected]> wrote:
> ----
> def __getattr__(self, name):
> # Assuming all templates end with .html
> path = name + '.html'
> t = self._lookup.get_template(path, globals={'_':_})
> return t.render
> ----
Sorry, 'globals=xxx' should be removed here. and finally, it works
now.
Just add 'translations' in render_jinja:
----
class render_jinja:
def __init__(self, *a, **kwargs):
extensions = kwargs.pop('extensions', [])
translations = kwargs.pop('translations', None) # Add
this line.
globals = kwargs.pop('globals', {})
from jinja2 import Environment,FileSystemLoader
self._lookup = Environment(loader=FileSystemLoader(*a,
**kwargs), extensions=extensions)
if translations is not None: # Add this line
self._lookup.install_gettext_translations(translations) #
Add this line
self._lookup.globals.update(globals)
----
in code.py:
----
from web.contrib.template import render_jinja
import gettext
from gettext import gettext as _
translation = gettext.translation('iredadmin', 'i18n', languages=
['zh_CN'])
render = render_jinja(
'templates',
extensions=['jinja2.ext.i18n'],
translations=lang_zh,
encoding = 'utf-8',
)
----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---