Alternatively, you can see if the parameter-based rewrite system will suit your needs, as it includes built-in support for language in the URL. Or you can track the user's chosen language via a cookie rather than the URL (doesn't help with bookmarking, though).
Anthony On Monday, July 11, 2016 at 12:17:02 PM UTC-4, Anthony wrote: > > > On Monday, July 11, 2016 at 11:46:54 AM UTC-4, Carlos Cesar Caballero > wrote: >> >> And he can't?? wait, I am lost. >> >> I need from some url like that: >> >> www.mysite.com/lang/ >> or >> www.mysite.com/lang/blog >> or >> www.mysite.com/lang/category >> >> to get 'lang' >> and do something like: >> var = get_lang() >> and late do: >> T.force(var) >> >> But how can I get lang? >> > > You need to write a regular expression to capture the language from the > incoming URL and then add it as a variable in the query string of the > rewritten URL (you may need separate rules for the case where the incoming > URL has vs. does not have an existing query string, as you need to add a > "?" to create the query string in the latter case, and you need an "&" in > the former case). > > Assuming you name the query string variable "_language", you would get it > in your code via request._language. Note, you would then have to add the > _language variable to all of your outgoing URLs (I would write a custom > url() function to do that automatically). > > Anthony > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.