Reputation: 979
My translations are working locally, but in production at Heroku, my site remains in its default language (English) after changing the language.
These are in my settings.py
file:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
This is my structure:
myproject
├── Procfile
├── locale
│ └── fr
│ └── LC_MESSAGES
│ ├── django.mo
│ └── django.po
├── myproject
│ ├── __init__.py
│ └── settings.py
I thought it was a path issue so I SSH'd into my Heroku app and printed LOCALE_PATHS
:
>>> from myproject.settings import LOCALE_PATHS
>>> print(LOCALE_PATHS)
['/app/locale']
And pwd
in locale/
returns pwd
/app/locale
.
What did I do wrong?
Upvotes: 0
Views: 721
Reputation: 150
The problem is that .mo
files (compiled translations) are not present in the repo, and therefore not packaged to be deployed together with the rest of the application during the Heroku build process.
The possible solutions are to:
.mo
files during the buildI suggest to generate them during the build, for these reasons:
To generate them, you can use the post compile hook of the Heroku build:
Create a file bin/post_compile
(no extension, like procfile) with the following line:
python ./manage.py compilemessages
Optionally you can add the specific language (e.g. python ./manage.py compilemessages -l nl
)
I got this last part from this answer to a similar question.
Upvotes: 0
Reputation: 979
I found the issue:
my django.mo
file was ignored by .gitignore
as I use the default GitHub Python gitignore file.
Upvotes: 4