So here is the full procedure I have been using.
1. As explained by Massimo and Wikus, in order to use two languages
(here French -fr- and English -en-) I wrote the following code in file
"routes.py" found in the "web2py" folder:
#---routes.py---#
routes_in = (
('/app/static/(?P<any>.*)','/app/static/$any'),
('/app/(en|fr)/(.*)',r'/app/default/\2/\1?_language=\1')
)
routes_out = (
('/app/static/(?P<any>.*)','/app/static/$any'),
('/app/default/(.*)/(en|fr)',r'/app/\2/\1')
)
#---------------#
where "app" has to be replaced by the actual name of the application
REMARKS:
I do not know why, but without the line in routes_in and routes_out:
('/llyow/static/(?P<any>.*)','/llyow/static/$any'),
which seems to be doing nothing (or not?) I get this error:
File "/home/aurelien/Documents/Webdesign/web2py/web2py/gluon/
rewrite.py", line 49, in load
for (k, v) in symbols['routes_in']:
ValueError: too many values to unpack
(Could someone explain what this line actually does, and why it seems
to be required?)
2. As explained by Massimo, I then added this line to my model:
if request.vars._language: T.force(request.vars._language)
3. I also provided links to switch manually between languages by
adding the following code in file "views/layout.html":
<a href="{{=URL(request.application,'en','index')}}">en</a>
<a href="{{=URL(request.application,'fr','index')}}">fr</a>
4. Finally I added a 'current' language argument to ALL the internal
links, like here for the "search" link:
{{=A(T('search'),_href=URL(r=request,f='search',args=[request.vars._language]))}}
It makes sure that thelanguage preference gets carried on through the
browsing session.
5. Finally, as I could not get it to work correctlv for French I tried
a few things and I then realised that I only had fr-fr.py in my
"languages" folder. I saved a copy of it that I named "fr.py" and it
did the magic. (What would be required to use a file like "fr-fr.py"
instead?)
That is about everything.
Thanks again for the ones who helped!
Aurelien
On 16 mar, 17:44, Wikus van de Merwe <[email protected]>
wrote:
> Aurelien, if your routes_in rule is:
> ('/app/(en|fr)/(.*)', r'/app/default/\2/\1')
>
> then for /app/fr/function you will get /app/default/function/fr
> and for /app/en/function/arg1/arg2 you will get /app/default/function/
> arg1/arg2/en
>
> Your rule for routes_out now should be:
> ('/app/default/(.*)/(en|fr)', r'/app/\2/\1')
>
> so for /app/default/function/fr you will get /app/fr/function
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.