激活金字塔中的平移

2024-05-15 03:50:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在金字塔框架中激活我的翻译。因此,我添加了翻译目录并设置了一个本地谈判者,如in https://stackoverflow.com/a/11289565/2648872和在http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/i18n.html#default-locale-negotiator中描述。另外,在我的ini文件中设置了默认和可用的语言,但是pyramid不接受我的翻译。我是否错过了激活翻译的功能?在

你好

托比亚斯

编辑

我的片段生产.ini在

[app:main]
use = egg:dbas

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = de

available_languages = de en

从我的init开始

^{pr2}$

此外,这些设置会被记录下来,并且默认的\u语言环境名称以及可用的语言都是可见的。不幸的是,在我的语言环境中,谈判者是不可读的:(

就像我的文件夹结构:

dbas
|- setup.py
|- development.ini
|- [...]
|-dbas
  |- __init__.py
  |- views.py
  |- [...]
  |- locale
    |- dbas.pot
      |- de
        |- LC_MESSAGES
        |- dbas.mo
        |- dbas.po
    |- en
      |- LC_MESSAGES
        |- dbas.mo
        |- dbas.po

Tags: pydebugpyramid语言falsedefaultdocs环境
2条回答

金字塔实际上找不到你的翻译目录。According to docs you need to pass absolute directory paths or asset specifications。我更喜欢资产规范,因为我也习惯于在视图配置中这样做。在

config.add_translation_dirs('dbas:locale') 

you are applying localization-related deployment settings起,您的用例不需要自定义区域设置谈判者。禁用金字塔配置中的自定义区域设置协商者。Rely on the pyramid implementation of the default locale negotiator。在

你只要need two things to activate translations。先应用这两个概念。在

为了调试,您可以use one these concepts to set locale manually。我真的很喜欢在查询字符串中传递LOCALE值。例如,拜访

^{pr2}$

解决了这个问题,因为我的宏结构变色龙模板是恶意的。在

相关问题 更多 >

    热门问题