diff --git a/pyramid_formalchemy/actions.py b/pyramid_formalchemy/actions.py index 010b8b9..17ea832 100644 --- a/pyramid_formalchemy/actions.py +++ b/pyramid_formalchemy/actions.py @@ -192,21 +192,32 @@ class Languages(Actions): """ >>> langs = Languages('fr', 'en') >>> langs - [, ] + [, ] >>> from webob import Request >>> request = Request.blank('/') + >>> request.cookies['_LOCALE_'] = 'fr' >>> request.route_url = lambda name, _query: 'http://localhost/set_language?_LOCALE_=%(_LOCALE_)s' % _query >>> print langs.render(request) #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE - fr - en +
  • French
  • +
  • English
  • """ + translations = { + 'fr': _('French'), + 'en': _('English'), + } def __init__(self, *args, **kwargs): list.__init__(self) klass=kwargs.get('class_', ListItem) for l in args: - self.append(Link(id=l, content=_(l), attrs=dict(href="request.route_url('set_language', _query={'_LOCALE_': '%s'})" % l))) + self.append( + klass(id=l, + content=self.translations.get(l, _(l)), attrs={ + 'class':"string:lang_%s ${request.cookies.get('_LOCALE_') == '%s' and 'lang_active' or ''}" % (l, l), + 'href':"request.route_url('set_language', _query={'_LOCALE_': '%s'})" % l + } + )) new = UIButton( id='new', diff --git a/pyramid_formalchemy/resources.py b/pyramid_formalchemy/resources.py index 203b9ac..351aa6d 100644 --- a/pyramid_formalchemy/resources.py +++ b/pyramid_formalchemy/resources.py @@ -33,6 +33,8 @@ class Base(object): if isinstance(langs, basestring): langs = langs.split() request.language_actions = actions.Languages(*langs) + else: + request.language_actions = actions.Actions() def get_model(self): diff --git a/pyramid_formalchemy/templates/admin/models.pt.py b/pyramid_formalchemy/templates/admin/models.pt.py index 917c257..792a359 100644 --- a/pyramid_formalchemy/templates/admin/models.pt.py +++ b/pyramid_formalchemy/templates/admin/models.pt.py @@ -2,14 +2,14 @@ registry = dict(version=0) def bind(): from cPickle import loads as _loads _lookup_attr = _loads('cchameleon.core.codegen\nlookup_attr\np1\n.') - _attrs_4360482000 = _loads('(dp1\n.') + _attrs_4358089040 = _loads('(dp1\n.') _init_scope = _loads('cchameleon.core.utils\necontext\np1\n.') _re_amp = _loads("cre\n_compile\np1\n(S'&(?!([A-Za-z]+|#[0-9]+);)'\np2\nI0\ntRp3\n.") + _attrs_4358088464 = _loads('(dp1\n.') _init_stream = _loads('cchameleon.core.generation\ninitialize_stream\np1\n.') + _attrs_4358088656 = _loads('(dp1\n.') _init_default = _loads('cchameleon.core.generation\ninitialize_default\np1\n.') - _attrs_4360481744 = _loads('(dp1\n.') - _attrs_4360481872 = _loads('(dp1\n.') - _attrs_4360482128 = _loads('(dp1\n.') + _attrs_4358088848 = _loads('(dp1\n.') _init_tal = _loads('cchameleon.core.generation\ninitialize_tal\np1\n.') def render(econtext, rcontext=None): macros = econtext.get('macros') @@ -31,7 +31,7 @@ def bind(): def _callback_main(econtext, _repeat, _out=_out, _write=_write, _domain=_domain, **_ignored): if _repeat: repeat.update(_repeat) - attrs = _attrs_4360481744 + attrs = _attrs_4358088464 u'models' _write(u'
    \n ') _tmp1 = econtext['models'] @@ -39,15 +39,15 @@ def bind(): (_tmp1, _tmp2, ) = repeat.insert('item', _tmp1) for item in _tmp1: _tmp2 = (_tmp2 - 1) - attrs = _attrs_4360481872 + attrs = _attrs_4358088656 _write(u'
    \n ') - attrs = _attrs_4360482000 + attrs = _attrs_4358088848 u"''" _write(u'
    \n ') _default.value = default = '' u'item' _content = item - attrs = _attrs_4360482128 + attrs = _attrs_4358089040 u'request.route_url(request.route_name, traverse=item)' _write(u'\n ') - attrs = _attrs_4358666448 + attrs = _attrs_4358301840 u'request.fa_url(request.model_name)' _write(u'
    ') _tmp1 = _content @@ -85,11 +85,11 @@ def bind(): _tmp = str(_tmp) _write(_tmp) _write(u'
    \n ') - attrs = _attrs_4358666640 + attrs = _attrs_4358302032 _write(u'

    \n ') - attrs = _attrs_4358666768 + attrs = _attrs_4358302160 _write(u'\n ') - attrs = _attrs_4358666896 + attrs = _attrs_4358302288 'join(value("F_(\'Save\')"),)' _write(u'\n \n ') - attrs = _attrs_4358666832 + attrs = _attrs_4358302224 u'request.fa_url(request.model_name)' _write(u'\n ') - attrs = _attrs_4358667024 - u"F_('Cancel')" + attrs = _attrs_4358302416 + u"'Cancel'" _write(u'\n ') - _tmp1 = econtext['F_']('Cancel') + _tmp1 = 'Cancel' _tmp = _tmp1 if (_tmp.__class__ not in (str, unicode, int, float, )): try: diff --git a/pyramid_formalchemy/views.py b/pyramid_formalchemy/views.py index fa09c89..2a1b652 100644 --- a/pyramid_formalchemy/views.py +++ b/pyramid_formalchemy/views.py @@ -238,14 +238,14 @@ class ModelView(object): ''' % dict(url=self.request.fa_url(self.request.model_name, _pk(item), 'edit'), - label=get_translator().gettext('edit')) + label=get_translator(request=self.request)('edit')) def delete_link(): return lambda item: '''

    ''' % dict(url=self.request.fa_url(self.request.model_name, _pk(item), 'delete'), - label=get_translator().gettext('delete')) + label=get_translator(request=self.request)('delete')) grid.append(Field('edit', fatypes.String, edit_link())) grid.append(Field('delete', fatypes.String, delete_link())) grid.readonly = True