In this article, I would like to show an example of how you can make a link on the site so that the user can switch between languages on the site.
But I will show a more advanced version of this functionality, namely saving the selected language in the user table, as well as redirecting the user to a page with the correct language that was selected by the user, if they are of course authorized. That is, if the user has set the German language for himself, then when going to the site via an English link, the site will automatically redirect the user to the page with the German language.
To do this, we need to add a language code field to the user model, I hope that everyone is already using their user model in Django instead of the default one.
Rewrite the standard Django language setup function, and also add a Middleware that will process the urls requested from the site.
Among other things, this functionality will be useful in order to generate letters with the correct language for registered users.
This article is based on Django 4 and may not be suitable for older versions of Django.