Felipe,
Well, if you don't prefix your urls with language code, Django will try
to match translated urls in the language retained for the session [1]
(black-box guessing).
I see multiple options, but the following is the less messy and seems to
fit your requirements:
# myproject.urls
from django.conf.urls import patterns, url
from django.utils.translation import ugettext_lazy as _
from help.views import HelpView
urlpatterns = patterns('',
url(_(r'^help/$'), HelpView.as_view(), name='help-view')),
url(r'^(help|ayuda)/$', HelpView.as_view())),
)
You keep first the translated named url for "reverse" sake then you add a
forgiving pattern pointing to the right view.
Anyway, I found usefull to experience the localised rendering for different reasons
(specific additions as legal informations, etc.) and you can easily propose a language
selection "widget". I find also the prefix good for many reasons but you
probably have your own ;)
Regards,
Michel
[1]
https://docs.djangoproject.com/en/dev/topics/i18n/translation/#how-django-discovers-language-preference
Le 10/02/2014 13:22, Felipe Mesquita de Oliveira a écrit :
Michel,
Thanks for you reply.
My ideia was to make it without the '/es/' or '/en/' starting the url.
Let's say a user share an 'es' link to an american user.
Like this: '/ayuda/'
I wanted the american user to be able to open it using language defined in
user's session ('en').
Thanks in advance,
Felipe
On Friday, February 7, 2014 11:23:39 PM UTC-2, werefrog wrote:
Hello,
I don't know where you're trying the troublesome reverse but maybe the
following can help.
# myproject.urls
from django.conf.urls import patterns, url
from django.utils.translation import ugettext_lazy as _
from django.conf.urls.i18n import i18n_patterns
from help.views import HelpView
urlpatterns = patterns('',
#
)
urlpatterns += i18n_patterns('',
url(_(r'^help/$'), HelpView.as_view(), name='help-view')),
url(_(r'^news/'), include('news.urls')), # can add namespace
)
# news.urls
from django.conf.urls import patterns, url
from django.utils.translation import ugettext_lazy as _
from .views import PageOneView, PageTwoView
urlpatterns = patterns('',
url(_(r'^$'), PageOneView.as_view(), name='news'),
url(_(r'^page-one/$'), PageOneView.as_view(), name='news-page-one'),
url(_(r'^page-two/$'), PageTwoView.as_view(), name='news-page-two'),
)
# test.py
from django.utils.translation import activate
activate('es')
#...
# resulting urls
/en/help/
/es/ayuda/
/en/news/
/en/news/page-one/
/en/news/page-two/
/es/noticias/
/es/noticias/pagina-um/
/es/noticias/pagina-dos/
Of course, you need to translate to spanish.
#
https://docs.djangoproject.com/en/dev/topics/i18n/translation/#message-files
python manage.py makemessages -l es
# python manage.py makemessages -a
# translate resulting file then …
#
https://docs.djangoproject.com/en/dev/topics/i18n/translation/#compiling-message-files
python manage.py compilemessages
Regards,
Michel
--
You received this message because you are subscribed to the Google Groups "Django
users" 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/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/52FA938B.7010907%40yahoo.fr.
For more options, visit https://groups.google.com/groups/opt_out.