Reputation: 1927
I read the documentation, read some blogs and started applying internationalization in my project, but it doesn't work. Probably something is going wrong. Please take a look what is it that I am doing wrong.
I am a windows user, so I started installing gettext versions both shared and static from this link.
then I made following changes in settings.py
:
LANGUAGE_CODE = 'fr'
MIDDLEWARE = [
"django.middleware.locale.LocaleMiddleware",
...
]
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale')
]
I already set the language code to French language. Then in my template namely index.html
I added following code:
{% load i18n %}
<!-- within block content -->
{% trans "Hi" %}
Now that everything is set I run following code in console:
django-admin makemessages -l fr
I received this message:
UnicodeDecodeError: skipped file requirements.txt in . (reason: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte)
processing locale fr
I have no idea if above stated error has anything to do with translating the text of the template. Anyway, then in django.po
within locale directory I translated that text of template to french as following:
#: .\templates\index.html:29
msgid "Hi"
msgstr "Salut"
and run django-admin compilemessages
, but when I run it the text is not translated. I don't know why? I followed every step for this basic setup.
Thank you for time and reading.
edit: This is the app structure of my project. Apologies that I don't know other way other than taking its screenshot. The translation content is in index.html
Upvotes: 1
Views: 377
Reputation: 106
Having a similar project structure, it worked for me set LOCALE_PATH to
LOCALE_PATH = (os.path.join(PROJECT_DIR, "locale"),)
and put my locale directory into portfolio/portfolio directory.
Upvotes: 1