Dear Niphlod,

This is right what I was looking for! :D
It's unbelievable how much I still have to learn about web2py. :)

Thanks a lot for this solution Niphlod!

Wish you a nice evening.
David


On 16 November 2012 21:36, Niphlod <[email protected]> wrote:

> ok, I played with it and understood an "underlying design" decision to let
> the current request.uri_language to propagate to all URL() generated links.
> In fact, parameter based router was thought to let "different" versions of
> the same site to behave in a consistent way (i.e., if you accessed
> myapp/it/something, it's likely that you'd like to navigate the entire site
> from there "mapped" to the it language).
>
> In this case, generating(showing) an url containing a different language
> is "forbidden" by the URL syntax.... but can be easily managed....just not
> using the URL() function :P
>
> You can use some replace with request.env.path_info, but I found a nicer
> method: you can in fact "alter" the language mapping of the URL just
> (re)setting the request.uri_language variable.
> I mean:
> /myapp/it/default/index
> URL('something', 'else') --> /myapp/it/something/else
> but:
> /myapp/it/default/index
> request.uri_language = 'jp'
> URL('something', 'else') --> /myapp/jp/something/else
>
> My advice would be to save the "actual" request.uri_language in some
> variable and altering that just to generate the URLs, then reset it back to
> the original value (so static and other links won't be 'altered', and you
> get the shortest possible link, etc etc) .... e.g.
>
> def index():
>     orig_lang = request.uri_lang
>     request.uri_lang = 'en'
>     this_page_in_eng_url = URL()
>     request.uri_lang = 'it'
>     this_page_in_it_url = URL()
>     request.uri_lang = orig_lang
> return dict()
>
>
>
>
>
>
>
>
> On Friday, November 16, 2012 8:33:34 PM UTC+1, David Sorrentino wrote:
>
>> Niphlod,
>>
>> I understand that web2py expects something like /a/lang/c/f or /lang/c/f,
>> but playing with request.something I didn't manage to obtain that. :)
>> Any tips?
>> Thanks for your help.
>>
>> Have a good night.
>> David
>>
>>
>> On 16 November 2012 15:25, Niphlod <[email protected]> wrote:
>>
>>> URL('it') is "go to the "it" function in the same controller I'm in".
>>> haven't played with that, but I guess web2py expects something like
>>> /a/lang/c/f so, by some means of request.something
>>> (function,controller,args,etc) you should be able to.....
>>>
>>>
>>>
>>> On Friday, November 16, 2012 12:23:52 PM UTC+1, David Sorrentino wrote:
>>>
>>>> Very last doubt, I promise! :P
>>>>
>>>> Let us assume that I am visiting the page at this url:
>>>>
>>>> /en/portfolio
>>>>>
>>>>
>>>> and I want to change to /it/portfolio, how can I set URL in order to do
>>>> that?
>>>> If I set it like this:
>>>>
>>>> URL('it')
>>>>>
>>>>
>>>> I will obtain:
>>>>
>>>> /en/it
>>>>>
>>>>
>>>> which is an invalid function.
>>>>
>>>> Cheers,
>>>> David
>>>>
>>>>
>>>> On 16 November 2012 11:33, David Sorrentino <[email protected]>wrote:
>>>>
>>>>> Hi Niphlod,
>>>>>
>>>>> Thanks for your example. It's crystal clear. ;)
>>>>> I got another doubt about multi-languages: on the online book I read
>>>>> that in order to tell web2py which language is the default one, I have to
>>>>> use:
>>>>>
>>>>> T.set_current_languages('it')
>>>>>>
>>>>>
>>>>> Now I am wondering if I need to use it in the controller and call it
>>>>> every time I load a page, or I can put it somewhere else and tell web2py
>>>>> just once which one is the default language.
>>>>>
>>>>> Sorry for all these doubts! :P
>>>>>
>>>>> Cheers,
>>>>> David
>>>>>
>>>>>
>>>>>
>>>>> On 15 November 2012 21:46, Niphlod <[email protected]> wrote:
>>>>>
>>>>>> I'd do the following
>>>>>> 1. choose a storage option for your content (you may want to use a
>>>>>> simple table with a 'text' field for editing online, or code something to
>>>>>> save the content to a "txt" file)
>>>>>> 2. code something that inspects the uri_language and does
>>>>>> (semi-programming-language):
>>>>>> if exists "nameoftherequestedarticle":
>>>>>>       if uri_language in "translationsofthearticle":
>>>>>>           content = translatedarticle
>>>>>>       else:
>>>>>>           content = originalarticle (english ?)
>>>>>> else:
>>>>>>     raise 404
>>>>>>
>>>>>>  --
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>  --
>>>
>>>
>>>
>>>
>>
>>  --
>
>
>
>

-- 



Reply via email to