Re: [web2py] Re: request.uri_language
Thanks Alan, Jonathan. I've test more this simple solution: routers = dict( BASE = dict(default_application=' test'), test = dict(languages=['en', 'it'], default_language='it'), ) And it works fine for me. The only problem I have now if for switching between two languages reloading the current function. If fact if I switch with (in my menu): {{response.menu.append(('IT', False, URL('it', 'index'), [('EN', False, URL('en', 'index'), [])]))}} It works fine. If I try with request.function, request.function give me the language + the function: {{response.menu.append(('IT', False, URL('it', request.function), [('EN', False, URL('en', request.function), [])]))}} So if I have mydomain.com/it and I ask for english, web2py tries to load mydomain.com/it/en . KO. Is there an elegant way to avoid this problem of do I have to play with a session variable ? Regards. Il giorno domenica 12 gennaio 2014 17:35:22 UTC+1, Jonathan Lundell ha scritto: On 12 Jan 2014, at 8:27 AM, Alan Etkin spam...@gmail.com javascript: wrote: I've got this server error: 200 Error My bad, unless you have specified the name or it is available in that scope, using app, test or whatever would raise a NameError. Perhaps it can be solved using a string (test) for the dictionary key. routers = { test: dict( default_language = possible_languages['default'][0], ... Alan is right; I was misreading the containing dict. -- 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/groups/opt_out.
Re: [web2py] Re: request.uri_language
On 13 Jan 2014, at 7:00 AM, Gael Princivalle gaelprinciva...@gmail.com wrote: Thanks Alan, Jonathan. I've test more this simple solution: routers = dict( BASE = dict(default_application=' test'), test = dict(languages=['en', 'it'], default_language='it'), ) And it works fine for me. The only problem I have now if for switching between two languages reloading the current function. If fact if I switch with (in my menu): {{response.menu.append(('IT', False, URL('it', 'index'), [('EN', False, URL('en', 'index'), [])]))}} It works fine. If I try with request.function, request.function give me the language + the function: {{response.menu.append(('IT', False, URL('it', request.function), [('EN', False, URL('en', request.function), [])]))}} So if I have mydomain.com/it and I ask for english, web2py tries to load mydomain.com/it/en . KO. Is there an elegant way to avoid this problem of do I have to play with a session variable ? There's apparently a deficiency in URL that makes this difficult for you. URL gets the language to insert into the outgoing URL from request.uri_language, and has no language argument to override it. That could and should be fixed. In the meantime, here's a hack you could use (not tested). It needs to be converted to template format, but you'll get the idea. uri_language = request.uri_language urls = {} for lang in ('it', 'en'): request.uri_language = lang urls[lang] = URL(request.function) request.uri_language = uri_language {{response.menu.append(('IT', False, urls['it'], [('EN', False, urls['en'], [])]))}} -- 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/groups/opt_out.
Re: [web2py] Re: request.uri_language
That's a good solution, thanks. In the meantime I've found that you have to specify with C=...the controller and f=... the functiuon in the URL helper. That like that it works fine: {{response.menu.append(('IT', False, URL('it', f=request.function), [('EN', False, URL('en', f=request.function), [])]))}} Thanks again for your help. Il giorno lunedì 13 gennaio 2014 16:22:50 UTC+1, Jonathan Lundell ha scritto: On 13 Jan 2014, at 7:00 AM, Gael Princivalle gaelpri...@gmail.comjavascript: wrote: Thanks Alan, Jonathan. I've test more this simple solution: routers = dict( BASE = dict(default_application=' test'), test = dict(languages=['en', 'it'], default_language='it'), ) And it works fine for me. The only problem I have now if for switching between two languages reloading the current function. If fact if I switch with (in my menu): {{response.menu.append(('IT', False, URL('it', 'index'), [('EN', False, URL('en', 'index'), [])]))}} It works fine. If I try with request.function, request.function give me the language + the function: {{response.menu.append(('IT', False, URL('it', request.function), [('EN', False, URL('en', request.function), [])]))}} So if I have mydomain.com/it and I ask for english, web2py tries to load mydomain.com/it/en . KO. Is there an elegant way to avoid this problem of do I have to play with a session variable ? There's apparently a deficiency in URL that makes this difficult for you. URL gets the language to insert into the outgoing URL from request.uri_language, and has no language argument to override it. That could and should be fixed. In the meantime, here's a hack you could use (not tested). It needs to be converted to template format, but you'll get the idea. uri_language = request.uri_language urls = {} for lang in ('it', 'en'): request.uri_language = lang urls[lang] = URL(request.function) request.uri_language = uri_language {{response.menu.append(('IT', False, urls['it'], [('EN', False, urls['en'], [])]))}} -- 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/groups/opt_out.
Re: [web2py] Re: request.uri_language
On 13 Jan 2014, at 7:48 AM, Gael Princivalle gaelprinciva...@gmail.com wrote: That's a good solution, thanks. In the meantime I've found that you have to specify with C=...the controller and f=... the functiuon in the URL helper. That like that it works fine: {{response.menu.append(('IT', False, URL('it', f=request.function), [('EN', False, URL('en', f=request.function), [])]))}} The only problem with that is that the rewrite code for languages wants to treat the language differently from the controller. It might work, but only because the rewrite code is more clever than I remember. Thanks again for your help. Il giorno lunedì 13 gennaio 2014 16:22:50 UTC+1, Jonathan Lundell ha scritto: On 13 Jan 2014, at 7:00 AM, Gael Princivalle gaelpri...@gmail.com wrote: Thanks Alan, Jonathan. I've test more this simple solution: routers = dict( BASE = dict(default_application=' test'), test = dict(languages=['en', 'it'], default_language='it'), ) And it works fine for me. The only problem I have now if for switching between two languages reloading the current function. If fact if I switch with (in my menu): {{response.menu.append(('IT', False, URL('it', 'index'), [('EN', False, URL('en', 'index'), [])]))}} It works fine. If I try with request.function, request.function give me the language + the function: {{response.menu.append(('IT', False, URL('it', request.function), [('EN', False, URL('en', request.function), [])]))}} So if I have mydomain.com/it and I ask for english, web2py tries to load mydomain.com/it/en . KO. Is there an elegant way to avoid this problem of do I have to play with a session variable ? There's apparently a deficiency in URL that makes this difficult for you. URL gets the language to insert into the outgoing URL from request.uri_language, and has no language argument to override it. That could and should be fixed. In the meantime, here's a hack you could use (not tested). It needs to be converted to template format, but you'll get the idea. uri_language = request.uri_language urls = {} for lang in ('it', 'en'): request.uri_language = lang urls[lang] = URL(request.function) request.uri_language = uri_language {{response.menu.append(('IT', False, urls['it'], [('EN', False, urls['en'], [])]))}} -- 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/groups/opt_out.
Re: [web2py] Re: request.uri_language
On 12 Jan 2014, at 7:51 AM, Gael Princivalle gaelprinciva...@gmail.com wrote: And this routes.py in test folder: from fileutils import abspath from languages import read_possible_languages possible_languages = read_possible_languages(abspath('applications', test)) routers = { test: dict( default_language = possible_languages['default'][0], languages = [lang for lang in possible_languages if lang != 'default'] ) } I've got this server error: 200 Error You want test = dict, not test: dict. -- 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/groups/opt_out.
Re: [web2py] Re: request.uri_language
On 12 Jan 2014, at 8:27 AM, Alan Etkin spame...@gmail.com wrote: I've got this server error: 200 Error My bad, unless you have specified the name or it is available in that scope, using app, test or whatever would raise a NameError. Perhaps it can be solved using a string (test) for the dictionary key. routers = { test: dict( default_language = possible_languages['default'][0], ... Alan is right; I was misreading the containing dict. -- 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/groups/opt_out.