You should definitely not call “translation.activate(‘fr’)” yourself, this will mask your real configuration issue. With LocaleMiddleware, Django should automatically choose the language based on the browser preferred language.
Each user has a preferred language in their profile (English or French).
The idea is that the app will switch to the user’s preferred language - ignoring the browser’s preferred language.
Is there a better way other than calling “translation.activate(<<users.preferred_language>>)”?
And, I still need LocalMiddleware to get the default language for the login page.
This page also has a language selector so the user can change to their language before logging in.
After logging in, the app should only display in the user’s language.
I think I would mimic Django and use the response.set_cookie() command that you can see in django.views.i18n.set_language, as soon as you redirect the user after login.
If I understand the docs correctly, set_cookie should not be necessary as I am using user sessions, but I followed the code in the examples.
This still didn’t not work and Django cannot find any of its own translations.
Given my deadline (and some desperation), I created a new .po file with the day and month translations from the django system file and put it on my LOCALE_PATHS.
This works, but there was a problem (more on that later).
My users don’t run as administrator, so this has little impact on the app as a whole.
It’s a scheduling application, so it is important that dates work
And finally, I noticed that in …/site-packages/django/conf/locale/fr/LC_MESSAGES/django.po, all the month and day translations appear to be commented out (those lines starts with #~).
I am not sure why this is, but I had to uncomment those lines to get my new django.po file to work.
This could have been my problem - my venv is in the same folder as my project, so compilemessages created a new django system .mo from the .po file.
But, that means that the the .po and .mo django system files aren’t consistent.
Or perhaps, the .po file was corrupted when I ran “makemessages” and it went through all the django directories.