i18n 在 heroku 的生产环境中不起作用 [英] i18n doesn't work at production environment on heroku

查看:17
本文介绍了i18n 在 heroku 的生产环境中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过一百多篇关于 i18n 问题的帖子,但似乎没有任何解决方案可以解决我的问题.

我有一个运行 Django 1.3.1 的应用程序,它在我的开发机器上运行良好.但是当我带到 heroku 时,什么也没有发生.这些文件根本没有翻译.我的项目中似乎找不到 locale 文件夹.

Locale 文件夹位于我的项目级别,这是我的设置:

BASE_PATH = os.path.dirname(os.path.abspath(__file__))LANGUAGE_CODE = 'pt-br'USE_I18N = 真USE_L10N = 真ugettext = lambda s: s语言 = (('en-us', ugettext('English')),('pt-br', ugettext('葡萄牙语')),)本地路径 = (os.path.join(BASE_PATH, "locale"),)

Locale 文件夹遵循以下结构:

语言环境pt_BRLC_MESAGESdjango.modjango.po

解决方案

在上面的示例中,您编写了 LC_MESAGES 而不是 LC_MESSAGES(注意双 S),我相信这很可能是您的问题.

如果没有,请继续阅读!

我最近遇到了这个问题(再次!),答案在 这部分 django 文档

我怀疑你有同样的问题,因为你的管理"应用程序被翻译了,但不是你自己的(项目)应用程序.

似乎 Django 正在像这样寻找您的翻译:

<块引用>

  1. LOCALE_PATHS 中列出的目录具有最高优先级,首先出现的优先级高于稍后出现.
  2. 然后,它会查找并使用是否存在语言环境INSTALLED_APPS 中列出的每个已安装应用程序中的目录.这首先出现的优先级高于出现的优先级稍后.
  3. 最后,Django 提供的基础翻译在django/conf/locale 用作后备.

使用上述设置,您必须确保您的树看起来像这样(最重要的是 settings.py 位于locale"目录上方的目录中):

+-project_top/|+-project_app/|||+-语言环境/|||||+-pt_BR/|||||+-LC_MESSAGES/|||||+-django.po|||+-settings.py|+-manage.py

I have seen more than one hundred posts about i18n issues and no solution seems to solve my problem.

I have an app running with Django 1.3.1 and it works Fine at my develop machine. But when I bring to heroku nothing happens. The files are not translated at all. It seems that the locale folder in my project is not being found.

Locale folder is at my project level and this is my settings:

BASE_PATH = os.path.dirname(os.path.abspath(__file__))

LANGUAGE_CODE = 'pt-br'

USE_I18N = True

USE_L10N = True

ugettext = lambda s: s
LANGUAGES = (
    ('en-us', ugettext('English')),
    ('pt-br', ugettext('Portuguese')),
)

LOCALE_PATHS = (
       os.path.join(BASE_PATH, "locale"),
)

Locale folder follows this structure:

locale
    pt_BR
        LC_MESAGES
            django.mo
            django.po

解决方案

In the sample above you wrote LC_MESAGES instead of LC_MESSAGES (notice the double S), I believe this very well could be your issue.

If not then read on!

I had this issue (again!) recently, and the answer was found in this part of the django documentation

I suspect you have the same issue since your "admin" app was translated but not your own (project) app.

It seems that Django is looking for your translations like so:

  1. The directories listed in LOCALE_PATHS have the highest precedence, with the ones appearing first having higher precedence than the ones appearing later.
  2. Then, it looks for and uses if it exists a locale directory in each of the installed apps listed in INSTALLED_APPS. The ones appearing first have higher precedence than the ones appearing later.
  3. Finally, the Django-provided base translation in django/conf/locale is used as a fallback.

With the settings you described above, you must make sure your tree looks something like this (with the most important being settings.py is in the dir above the 'locale' dir):

+-project_top/
  |
  +-project_app/
  | |
  | +-locale/
  | | |
  | | +-pt_BR/
  | |   |
  | |   +-LC_MESSAGES/
  | |     |
  | |     +-django.po
  | |  
  | +-settings.py
  |
  +-manage.py

这篇关于i18n 在 heroku 的生产环境中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆