Re: [flask] Flask-Babel and using url prefix
- From:
- anh le
- Date:
- 2010-10-27 @ 08:22
Hi,
On Wed, Oct 27, 2010 at 2:55 PM, Armin Ronacher <armin.ronacher@active-4.com
> wrote:
> Hi,
> On 10/27/10 9:44 AM, anh le wrote:
> > Can app.register_module(admin, url_prefix='<lang>') do that?
> Yes, you need a trailing slash though:
>
> app.register_module(admin, url_prefix='/<lang>')
>
> You could also subclass Flask to override the route function to always
> prefix the URL rule with "/<lang>" unless a certain parameter is set.
>
Thanks Armin, subclassing Flask is a propably the good way to implement my
stuffs.
Regarding app.register_module, I mean the '<lang>' is a parameter,
not fixed. Can a module be registered with a paramterized url_prefix and
function get_locale could extract that prefix.
Regards,
Re: [flask] Flask-Babel and using url prefix
- From:
- Armin Ronacher
- Date:
- 2010-10-27 @ 08:24
Hi,
On 10/27/10 10:22 AM, anh le wrote:
> Regarding app.register_module, I mean the '<lang>' is a parameter,
> not fixed. Can a module be registered with a paramterized url_prefix and
> function get_locale could extract that prefix.
Yes, that is possible. There is no restriction on the prefix.
Regards,
Armin
Re: [flask] Flask-Babel and using url prefix
- From:
- Tijmen Mulder
- Date:
- 2010-10-27 @ 08:41
Hi,
I need a language code at all times but i don't want to hande the language
code in my views so i did a little @app.before_request middleware with:
language_code = request.view_args.pop('language_code', None)
g.context['language_code'] = language_code
I've also overridden url_for to add:
if endpoint != 'static':
if not 'language_code' in values:
values['language_code'] = g.context['language_code']
Then in @babel.localeselector:
return g.context['language_code']
Works great.
Regards,
On Wed, Oct 27, 2010 at 10:24 AM, Armin Ronacher <
armin.ronacher@active-4.com> wrote:
> Hi,
>
> On 10/27/10 10:22 AM, anh le wrote:
> > Regarding app.register_module, I mean the '<lang>' is a parameter,
> > not fixed. Can a module be registered with a paramterized url_prefix and
> > function get_locale could extract that prefix.
> Yes, that is possible. There is no restriction on the prefix.
>
>
> Regards,
> Armin
>