Access to matchdict on locale_negotiator

15 views
Skip to first unread message

Juan Pizarro

unread,
Aug 9, 2011, 3:33:01 PM8/9/11
to pylons-devel
Hello,

My name is Juan Pizarro, from Chile.

I'm working to migrate a app form pylons to pyramid, i use mako and
the locale is based on URL, example /{lang}/place/{id}.

The problem is, I can't access to the request.matchdict on
locale_negotiator, there aren't exist,

The solution was to setup the locale_name in a suscriber on
pyramid.events.BeforeRender, like
request.locale_name = request.matchdict['lang'] if 'lang' in
request.matchdict else None

I don't know if this is a good option, but works.

I don't know if is a bug or pyramid was designed for setup matchdict
after locale_negotiator.

Bye

Blaise Laflamme

unread,
Aug 9, 2011, 9:41:14 PM8/9/11
to pylons-devel
You can use a custom predicate in your routes to set
request.locale_name, try something like:

def langs(info, request):
lang = info['match'].get('lang')
if lang:
request.locale_name = lang
return True
return False

and add route:

config.add_route('place', '/{lang}/place', custom_predicates=(langs,))

Hope this helps,

Blaise
Reply all
Reply to author
Forward
0 new messages