views_translate = {
# Controllers Names
'default' : 'principal',
'principal' : 'default',
'articles' : 'artigos',
'artigos' : 'articles',
# Function Names
'index' : 'inicio',
'inicio' : 'index',
'new' : 'novo',
'novo' : 'new',
'search' : 'procurar',
'procurar' : 'search',
}
controllers_translate = {
'default' : T('default', lazy=False),
'principal' : T('default', lazy=False),
'articles' : T('articles', lazy=False),
'artigos' : T('articles', lazy=False),
}
functions_translate = {
'index' : T('index', lazy=False),
'inicio' : T('index', lazy=False),
'new' : T('new', lazy=False),
'novo' : T('new', lazy=False),
'search' : T('search', lazy=False),
'procurar' : T('search', lazy=False),
}
#Translate Views
if T.accepted_language != 'en' and request.extension and request.extension == 'html':
response.view = '%s/%s.html' % (views_translate[request.controller], views_translate[request.function])
#Redirect controllers and functions if necessary
if not T.accepted_language == 'en':
if request.controller != controllers_translate[request.controller] or request.function != functions_translate[request.function]:
redirect(URL(scheme='https', host=True, r=request, c=controllers_translate[request.controller], f=functions_translate[request.function], args=request.args, vars=request.vars), how=301)
else:
if request.controller != controllers_translate[request.controller] or request.function != functions_translate[request.function]:
redirect(URL(scheme='https', host=True, r=request, c=controllers_translate[request.controller], f=functions_translate[request.function], args=request.args, vars=request.vars), how=301)
{{=URL(r=request, c=T('articles', lazy=False), f=T('search', lazy=False))}}
$ ln default.py principal.py
$ ln articles.py artigos.py
def inicio():
return index()
def novo():
return new()
def procurar():
return search()
I have this in models till now:
views_translate = {
# Controllers Names
'default' : 'principal',
'principal' : 'default',
'articles' : 'artigo',
'artigo' : 'articles',
# Function Names
'index' : 'inicio',
'inicio' : 'index',
'new' : 'novo',
'novo' : 'new',
'search' : 'procurar',
'procurar' : 'search',
}
controllers_translate = {
'default' : T('default', lazy=False),
'principal' : T('default', lazy=False),
'articles' : T('articles', lazy=False),
'artigo' : T('articles', lazy=False),
}
functions_translate = {
'index' : T('index', lazy=False),
'inicio' : T('index', lazy=False),
'new' : T('new', lazy=False),
'novo' : T('new', lazy=False),
'search' : T('search', lazy=False),
'procurar' : T('search', lazy=False),
}
#Translate Views
if T.accepted_language != 'en' and request.extension and request.extension == 'html':
response.view = '%s/%s.html' % (views_translate[request.controller], views_translate[request.function])
#Redirect controllers and functions if necessary
if not T.accepted_language == 'en':
if request.controller != controllers_translate[request.controller] or request.function != functions_translate[request.function]:
redirect(URL(scheme='https', host=True, r=request, c=controllers_translate[request.controller], f=functions_translate[request.function], args=request.args, vars=request.vars), how=301)
else:
if request.controller != controllers_translate[request.controller] or request.function != functions_translate[request.function]:
redirect(URL(scheme='https', host=True, r=request, c=controllers_translate[request.controller], f=functions_translate[request.function], args=request.args, vars=request.vars), how=301)
But on the views I also have to assign translation for every URL() function:
{{=URL(r=request, c=T('articles', lazy=False), f=T('search', lazy=False))}}
is there a better way to do this?
--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Very interesting question. It must have some effect on SEO.I have seen this post but it does not seem to solve exactly this
There's also the alternative of embedding a language code in the URL and not translating the URL elements. The parameter-based routing system already supports that, and it would give you separate search-engine indexing.