Hi, You were right that I was using ugettext instead of ugettext_lazy. Thank you for your response and for your suggestions on the code.
Regards, Jorge On Thursday, May 15, 2014 9:09:18 PM UTC+2, Tomáš Ehrlich wrote: > > Hi, > use ugettext_lazy for translation of urls, models and other stuff which > is loaded before language is determined (it's usually done in > Middleware or later in view, otherwise all strings will be translated > into default language). > > You can also write: > > url(_(r'^about$'), views.about, name='about'), > > which is easier to read and you can see in your .po file, that you are > translating url. > > > Cheers, > Tom > > > Dne Thu, 15 May 2014 11:24:41 -0700 (PDT) > Jorge Cardoso Leitão <jorgeca...@gmail.com <javascript:>> napsal(a): > > > Hi. > > > > I'm trying to reverse urls to other languages and I'm having some > > difficulties: > > > > Consider a new project in python 3.3 Django 1.6.4 with the adittional > > settings > > > > LOCALE_PATHS = (BASE_DIR + '/locale',) > > > > LANGUAGE_CODE = 'en-us' > > LANGUAGES = ( > > ('en-us', 'English'), > > ('de', 'German'), > > ) > > > > > > The following views.py: > > > > def home(request): > > from django.utils import translation > > from django.utils.translation import ugettext as _ > > > > > > > > translation.activate('de') > > print(reverse("about")) > > print(_('search')) > > > > render(request, 'home.html') > > > > def about(request): > > render(request, 'about.html') > > > > and the following urls.py: > > > > urlpatterns = patterns('', > > url(r'^$', views.home, name='home'), > > url(r'^%s$' % _('about'), views.about, > name='about'), > > > > > > After running make_messages, translate the strings in .po, > compile_messages > > and restart the server, > > going to / prints the following in the console: > > > > >> /about > > > > >> [translation of "search"] > > > > > > I.e. even though "about" is translatable, it is not being translated; my > > objective is to have > > it translated to a german url. > > > > I tried going as far as using > > > > from django.conf import settings > > urlconf = settings.ROOT_URLCONF > > resolver = RegexURLResolver(r'^/', urlconf) > > > > print(resolver._reverse_with_prefix(about, '/')) > > > > or even > > > > temp = __import__(urlconf, globals(), locals(), [], 0) > > print(getattr(temp.urls, "urlpatterns")) > > > > but they are all giving me the untranslated url. > > > > I digged into the core.urlresolvers.py, and it RegexURLPattern.regex is > > always returning the en-us pattern, even when the language_code is 'de'. > > > > I then went to see why, and it seems the urls.py are always being > imported > > in the en version, even after the translation.activate('de') call. > > > > Does anyone know if this is the intended behavior, or if there a way to > > change it? > > > > Thanks a lot, > > Jorge > > > -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. 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/c9389fce-b29d-483f-9b8e-4169807689ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.