gettext 翻译不适用于生产系统

发布于 2024-09-30 21:20:39 字数 437 浏览 8 评论 0原文

我在使用 django 的 gettext 翻译字符串(在管理中)时遇到了一个奇怪的问题:本地运行开发服务器,所有翻译都在管理中正确显示,但是当项目部署在生产服务器上时一些字符串根本没有被翻译。我无法确定哪些系统背后的字符串受到影响,哪些不受影响!

给你一个印象,例如。模型的定义如下:

class Company(models.Model):

    ....

    class Meta:
        verbose_name = _('Company Profile')
        verbose_name_plural = _('Company Profiles')

使用开发服务器,模型的名称在管理中以不同语言正确显示,但在生产服务器上则不然!这会影响某些模型,而其他模型则不会...这让我非常抓狂,因为我几乎不知道如何调试它...

I've encountered a strange problem when translating strings (in the admin) using django's gettext: Locally running the dev server all translations are displayed correctly in the admin, but when the project is deployed on the production server some strings are not translated at all. I cannot determine any system behind which strings are affected and which not!

To give you an impression, eg. a model is defined like:

class Company(models.Model):

    ....

    class Meta:
        verbose_name = _('Company Profile')
        verbose_name_plural = _('Company Profiles')

Using dev server the model's name shows up correctly in different languages in the admin, on the production server not! This affects some models, others not... This is driving me really nuts, since I hardly have a idea on how to debug this...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉生梦死 2024-10-07 21:20:39

一些可能性:

  • 生产服务器看不到已编译的消息
  • 未翻译的消息被标记为模糊
  • _()解析为ugettext而不是ugettext_lazy

A few possibilities:

  • production server doesn't see the compiled messages
  • the untranslated messages are marked as fuzzy
  • _() resolves to ugettext instead of ugettext_lazy
流云如水 2024-10-07 21:20:39

我遇到了类似的问题,除了 Tomasz Zielinski 指出的之外,我还必须进行以下更改:

在 settings.py 中

LOCALE_PATHS = (
    "/path/to/your/project/locale",
)

记住尾随斜杠并确保目录结构如下所示:

project
   your_app
   your_other_app
   locale
      en_US
          LC_MESSAGES
      sv_SE
          LC_MESSAGES

I had a similar problem and apart from what Tomasz Zielinski pointed out I had to make the following changes:

in settings.py

LOCALE_PATHS = (
    "/path/to/your/project/locale",
)

Remember the trailing slash and make sure that the directory structure looks something like:

project
   your_app
   your_other_app
   locale
      en_US
          LC_MESSAGES
      sv_SE
          LC_MESSAGES
隱形的亼 2024-10-07 21:20:39

如果您在 Windows 上进行开发并且生产实例是 Linux,那么问题可能是:在文件路径命名方面,Windows 不区分大小写,而 Linux 区分大小写。

例如,区域设置文件夹名称应为:

  • zh_Hans 而不是 zh_hans
  • pt_BR 而不是 pt_br

If you are developing on Windows and the production instance is Linux, then the problem might be: Windows is not case sensitive while Linux is case sensitive, in terms of naming of file paths.

For example, a locale folder name should be:

  • zh_Hans instead of zh_hans
  • pt_BR instead of pt_br
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文