On Django 1.4, I want to have two languages in my site, turkish('tr') and english('en').
This is my current setup:
settings.py:
USE_I18N = True
LANGUAGES = (
('en', 'English'),
('tr', 'Turkish'),
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware', # I have locale middleware
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
LOCALE_PATHS = (
'/myproject/locale/',
)
And I have my locale files as such directory order:
#tr files
/myproject/locale/tr/LC_MESSAGES/django.mo
/myproject/locale/tr/LC_MESSAGES/django.po
#en files
/myproject/locale/en/LC_MESSAGES/django.mo
/myproject/locale/en/LC_MESSAGES/django.po
And I still cannot see my translations, trying from my shell (it also doesn't work for templates as {% trans "Corporate" %}):
>>> from django.utils import translation
>>> translation.activate('tr')
>>> translation.ugettext('Corporate')
u'Corporate'
Am I missing anything here? Weirdly, it translates for words like 'Home' as original Django has translations for these but not my translation files.
In your case you must put into LOCALE_PATHS
absolute path to your locale directory, i.e.
LOCALE_PATHS = (
'/home/path_to_your_project/myproject/locale/',
)
I guess you've tried to set relative path there.
I had similiar problem: i've been using django 1.3 and my locale directory was in the root of my project, i.e. near settings.py and manage.py files.
But when i create project with django 1.4, project directory structure have been changed: settings.py have moved into myproject/myproject folder. I still create locale
folder in myproject/ (not in myproject/myproject). And with django 1.4 it is not working any more.
Reading documentation i understand, that django just can't find my locale
folder. So solution that helps me - either move locale
dir into myproject/myproject and don't set any LOCALE_PATHS
OR leave locale
dir in myproject/ path and add full path to it in settings.py in LOCALE_PATHS
tuple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With