1

The translation works on my own computer, but when the website is deployed to AWS Elastic Beanstalk, it does not work anymore...

I have followed the Django v1.9 documentation. Mark the translation string by {% trans %}, generate the message file and compile it, add the locale path and middleware in the settings.py file.

MIDDLEWARE CLASSES:

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

LOCALE PATH: (I just tried different path, the directories contain identical message files.)

LOCALE_PATHS = [
os.path.join(BASE_DIR, "locale/"),
os.path.join(BASE_DIR, "translations/locale/"),
]

File structure:

myproject/
    manage.py
    myproject/
        settings.py
    locale/
        zh_HANT/
           LC_MESSAGES/
               django.po
               django.mo
    translation/
        locale/
           zh_HANT/
               LC_MESSAGES/
                  django.po
                  django.mo
    account_management/

LANGUAGE SETTING:

LANGUAGE_CODE = 'en-us'
LANGUAGES = [
    ('zh-hant', _('Traditional Chinese')),
    ('en', _('English')),
]
USE_I18N = True
USE_L10N = True
USE_TZ = True

urls.py

urlpatterns += i18n_patterns(
   url(r'^', include('account_management.urls')),
)

Error shown in AWS log:

`[Thu Apr 21 21:02:30.179229 2016] [:error] [pid 16295] ('locale_path', '/opt/python/current/app/locale/')
 [Thu Apr 21 21:02:30.179235 2016] [:error] [pid 16295] ('locale_path', '/opt/python/current/app/translations/locale/')`

Is this a django issue or the configuration problem of the AWS? I tested the website on my Windows computer, but the server on AWS is running Linux, does this matter? Please advise...

  • Most probably its a path problem. See my answer here => http://stackoverflow.com/questions/20518783/django-1-5-5-displays-original-en-strings-always-does-not-translate (especially the ../locale part) – Serafeim Apr 19 '16 at 19:45
  • I have tried it, but still does not work... I tried both: BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) – Kelvin Kong Apr 19 '16 at 19:58
  • What do the server logs say? If the application is looking for a translation, and its not there you should be getting an error of some sort (ie a 404 which will tell you where its looking for the file, if at all). Just by what you've said I feel its a path issue too... Is the BASE_DIR properly set? Do you need a leading "/" on the locale path directory? – hephalump Apr 19 '16 at 21:26
  • Sorry I finally find out the error message. Hope that it helps. [Thu Apr 21 21:02:30.179229 2016] [:error] [pid 16295] ('locale_path', '/opt/python/current/app/locale/') [Thu Apr 21 21:02:30.179235 2016] [:error] [pid 16295] ('locale_path', '/opt/python/current/app/translations/locale/') Adding a leading "/" to the path will go to the root directory. I tested it and it did not work. – Kelvin Kong Apr 21 '16 at 21:06

0 Answers0