On May 1, 2012, at 4:27 PM, ender72 wrote:
> Hi,
> I'm reading "web2py application development cookbook",
> page 277
> "To specify a language for outgoing URLs using URL(), set request.lang to one
> of the supported languages [...]".
The book (and the example documentation) are wrong; not sure how that slipped
through.
Use URL(..., lang='it')
The incoming language (from the incoming URL) is stored in request.language.
The outgoing language ends up in request.uri_language, but it's best to specify
it as an argument to URL().
Notice that it's up to you to connect these to the translation system; that's
not currently automatic, I don't think.
>
> Mmm... maybe something's wrong, because if I put this code in a view:
>
> {{
> request.lang='it'
> link_it = URL('about', 'index')
> request.lang='en'
> link_en = URL('about', 'index')
> request.lang='fr'
> link_fr = URL('about', 'index')
> }}
> {{=link_it}}, {{=link_en}}, {{=link_fr}}
>
> results are:
> /en/azienda, /en/azienda, /en/azienda
> (if request.url is http://127.0.0.1:8000/app/en/<controller>/<function>/)
> or
> /it/azienda, /it/azienda, /it/azienda
> (if request.url is http://127.0.0.1:8000/app/it/<controller>/<function>/)
> etc...
>
> my routes.py is
>
> routers = dict(
> BASE = dict(
> default_application='app',
> default_controller = 'home',
> default_function = 'index'
> ),
> casal = dict(
> map_hyphen = True,
> languages = ['it', 'en', 'fr'],
> default_language = 'it',
> ),
> )
>
>
> Thanks.