简体   繁体   English

激活金字塔翻译

[英]Activate Translation in Pyramids

I want to activate my translations in pyramids framework. 我想在金字塔框架中激活我的翻译。 Therefore I have added the translation directorys and set a local negotiator like in https://stackoverflow.com/a/11289565/2648872 and desribed in http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/i18n.html#default-locale-negotiator . 因此,我添加了翻译目录并设置了本地协商程序,例如https://stackoverflow.com/a/11289565/2648872,并在http://docs.pylonsproject.org/docs/pyramid/zh-CN/latest/narr/中进行了描述i18n.html#default-locale-negotiator Additionally the default and available language in my ini files are set, but pyramid wont accept my translations. 另外,我的ini文件中设置了默认语言和可用语言,但是pyramid不接受我的翻译。 Do i miss something for activating translations? 我会错过一些激活翻译的东西吗?

Greetings 问候

Tobias 托比亚斯

Edit : 编辑

Snippet of my production.ini 我的production.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

And out of my init .py: 从我的init .py中:

def main(global_config, **settings):
[...]
config = Configurator(settings=settings,root_factory='dbas.database.RootFactory') 
config.add_translation_dirs('locale') 
[...]
config.set_locale_negotiator(my_locale_negotiator)

Additionally the settings are logged, and default_locale_name as well as available_languages are visible. 另外,将记录设置,并且可见default_locale_name和available_languages。 Unfortunately in my_locale_negotiator, they are not readable :( 不幸的是,在my_locale_negotiator中,它们不可读:(

My folder structure is like: 我的文件夹结构如下:

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

Pyramid actually does not find your translation dirs. 金字塔实际上找不到您的翻译目录。 According to docs you need to pass absolute directory paths or asset specifications . 根据文档,您需要传递绝对目录路径或资产规范 I prefer an asset specification, since I am used to do this for view configuration as well. 我更喜欢资产规范,因为我也习惯于进行视图配置。

config.add_translation_dirs('dbas:locale') 

You do not need a custom locale negotiator for your use case since you are applying localization-related deployment settings . 因为您正在应用与本地化相关的部署设置,所以不需要用例的自定义语言环境协商程序。 Disable the custom locale negotiator in the pyramid configuration. 在金字塔配置中禁用自定义语言环境协商程序。 Rely on the pyramid implementation of the default locale negotiator . 依靠默认语言环境协商程序的金字塔实现

You just need two things to activate translations . 您只需要两件事就可以激活翻译 Only apply these two concepts first. 仅首先应用这两个概念。

For debugging purpose you can use one these concepts to set locale manually . 为了进行调试,您可以使用以下概念之一来手动设置区域设置 I really liked passing a LOCALE value in the query string. 我真的很喜欢在查询字符串中传递LOCALE值。 For example, visiting 例如,访问

http://my.application?_LOCALE_=de

解决了此问题,导致我的变色龙模板宏结构被恶意破坏了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM