3

I'm currently writing an app in Django and I'm using the default django.contrib.auth for the users. I'm currently doing the internationalization. I already generated the locale files and it's working well with my custom urls, but it's not working for the auth urls (e.g., login, password_reset, reset/done/). Is it possible to override those?

Here are my files:

settings.py:

LOCALE_PATHS = [ os.path.join(BASE_DIR, 'locale'), ]

urls.py:

 re_path(_(r'^users/'), include('django.contrib.auth.urls')),

django.po:

#: users/urls.py:10
msgid "^login/$"
msgstr "^iniciar_sesion/$"
c6754
  • 870
  • 1
  • 9
  • 15
  • Have you tried wrapping with [i18n_patterns](https://docs.djangoproject.com/en/2.1/topics/i18n/translation/#translating-url-patterns)? `urlpatterns += i18n_patterns(re_path(_(r'^users/'), include('django.contrib.auth.urls')))`, – dirkgroten Sep 24 '18 at 14:44
  • I recently had the same problem and I solved it with this solution: https://stackoverflow.com/questions/7878028/override-default-django-translations/20439571#20439571 – Magda Sep 24 '18 at 16:08
  • @Magda the question is about translating the URLs, not overriding Django's default translations. But probably your link will help too, once he discovers the default translations aren't the best. – dirkgroten Sep 24 '18 at 17:04
  • It's about overriding the default URLs, specifically for `django.contrib.auth` that it's the only Django component that I'm using. @dirkgroten I have all my patterns wrapped in `i18n_patterns` and it's working well for my other apps. I think the problem is when I run the `django-admin compilemessages` command because the admin compiles all the .po files of the contribs libraries. – J. Esteban Castillo Sep 24 '18 at 20:01
  • What do you mean by overriding URLs? Keep the same English URLs and just change their translation? Or change the URL to something completely different (also translated) ? – dirkgroten Sep 24 '18 at 20:04
  • Change the URL to something completely different. For example, my URL for the login is `en/users/login` but in Spanish I need `es/usuarios/iniciar_sesion`. Currently it translates the URL to `es/usuarios/login` and it's happening with all the URL's related to auth, like `password_reset`, `reset/done/`, etc. – J. Esteban Castillo Sep 24 '18 at 20:10

0 Answers0