Reputation: 1219
I have read the documentation from django on how to make your website available in more languages.
To be honest all sounds really complicated so I need help to clear everything.
First of all, I would like to do the following:
website.com/en/index
website.com/es/index
etc. I found this project but seems out of date and I am looking if there is any built-in way to do the same.website.com/es/index
, clicking then the website's url how can I ensure that will follow the same langauge that the user entered into the website?I am not looking someone to solve my problems but rather to put me in the right direction for the following:
Thank you in advance.
Upvotes: 0
Views: 502
Reputation: 7924
You don't need any third party package to accomplish what you want to do, Django has it built-in.
django.middleware.locale.LocaleMiddleware
to your middlewares,urls.py
with django.conf.urls.i18n.i18n_patterns
,and you are done.
You get urls like site.com/en/lorem-ipsum
for the urls you wrapped with django.conf.urls.i18n.i18n_patterns
.
To be more specific about your questions:
1) This is the default behaviour. If you wrap admin url with django.conf.urls.i18n.i18n_patterns
, you'll get admin site in multiple languages, too. With the same url style, like site.com/en/admin/
. Here is an example urls.py
:
from django.conf.urls import url, include, i18n
from django.contrib import admin
urlpatterns += i18n.i18n_patterns(
url(r'^admin/', admin.site.urls),
url(r'^products/', include('your_project.apps.products.urls', namespace='products')),
# ...
)
2) The all urls will be consistent locale-wise. E.g. if the user is on site.com/en/home
and there is a link to the about products page the link will be `site.com/en/about'
3) I can understand, it would be a lot easier to update translations on admin site without editing gettext files and such. However, I like the way django handles translation. Making translation something about admin site would involve database and I don't think it is a good idea to use database for translation.
Upvotes: 1