翻译在我自己的计算机上运行,但当网站部署到AWS Elastic Beanstalk时,它不再起作用了......
我已经关注了Django v1.9文档。通过{%trans%}标记翻译字符串,生成消息文件并进行编译,在settings.py文件中添加语言环境路径和中间件。
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 :(我刚尝试了不同的路径,目录中包含相同的消息文件。)
LOCALE_PATHS = [
os.path.join(BASE_DIR, "locale/"),
os.path.join(BASE_DIR, "translations/locale/"),
]
文件结构:
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_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')),
)
AWS日志中显示错误:
`[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/')`
这是django问题还是AWS的配置问题?我在我的Windows计算机上测试了该网站,但AWS上的服务器正在运行Linux,这有关系吗?请指教......