Hi, thanks a lot for your answer and sorry for getting back so horribly late.
I had not think of that, and it looks like something I could use, it is way simpler than what I have now. If I get a solution for this I will post it here. Thank you. On Saturday, March 1, 2014 8:13:20 PM UTC+1, Sontek wrote: > > Have you considered writing your own function `add_localized_route` and > `localized_view_config`? > > This is by no means a fully thought out implementation but some psuedo > code to get you thinking, but something like this could work: > > languages = ['en', 'es', 'de'] > > def add_localized_route(config, name, *args, **kwargs): > for lang in languages: > localizer = Localizer(lang) > translated_name = localizer.translate(name) > config.add_view(translated_name, *args, **kwargs) > > and you would do the same thing for a custom view_config decorator. > > > On Tue, Feb 18, 2014 at 4:33 AM, <[email protected] <javascript:>>wrote: > >> Hi all, >> >> I am trying to have my routes in several languages (/en/products, >> /es/productos, etc) but I can't come up with an >> easy way of doing that. >> >> One option would be to write all the routes in every language, but that >> would be too cumbersome since >> it is not possible to link two routes with the same name and different >> paths. >> >> config.add_route('products', '/en/products/{id:\d+}', ...) >> config.add_route('productos', '/es/productos/{id:\d+}', ...) >> ... >> @view_config(route_name='products') >> @view_config(route_name='productos') >> def products(self): >> ... >> >> If the replacement markers are strings instead of numbers, well, it gets >> harder. And in the real >> application replacement markers are being used heavily. >> >> So, the question: is there any way of having the route automagically >> translated to the default language? >> What I would like to do is something similar to >> >> config.add_route('products', _('/{language}/products/{id:\d+}'), ...) >> ... >> @view_config(route_name='products') >> def products(self): >> >> but I'm afraid it will add the (translated) routes when loaded, and not >> all the routes. >> >> Of course, if this is not possible, I will have /{language}/products >> (products will appear only in english) >> as a path, but I would like to know if there are more options. >> >> The only somewhat related information that I have found are these two >> articles: >> http://codeistan.com/2012/02/18/localization-in-pyramid.html >> http://my.opera.com/WebApplications/blog/2008/03/17/search-engine-friendly >> >> however, I have seen that in other web frameworks it is possible (with >> some effort) to do this, >> so that led me to think that maybe I'm missing something really obvious >> about Pyramid here. >> >> Thank you very much. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "pylons-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> Visit this group at http://groups.google.com/group/pylons-discuss. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
