在金字塔中激活平移
Activate Translation in Pyramids
我想在金字塔框架中激活我的翻译。因此我添加了翻译目录并设置了一个本地谈判者,就像 and desribed in http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/i18n.html#default-locale-negotiator 中那样。此外,我的 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
从我的 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)
此外,设置会被记录下来,并且 default_locale_name 和 available_languages 都可见。不幸的是,在 my_locale_negotiator 中,它们不可读 :(
我的文件夹结构如下:
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 实际上没有找到你的翻译目录。 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. Disable the custom locale negotiator in the pyramid configuration. 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 值。例如,访问
http://my.application?_LOCALE_=de
解决了这个问题,因为我的变色龙模板宏结构是恶意的。
我想在金字塔框架中激活我的翻译。因此我添加了翻译目录并设置了一个本地谈判者,就像 and desribed in http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/i18n.html#default-locale-negotiator 中那样。此外,我的 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
从我的 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)
此外,设置会被记录下来,并且 default_locale_name 和 available_languages 都可见。不幸的是,在 my_locale_negotiator 中,它们不可读 :(
我的文件夹结构如下:
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 实际上没有找到你的翻译目录。 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. Disable the custom locale negotiator in the pyramid configuration. 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 值。例如,访问
http://my.application?_LOCALE_=de
解决了这个问题,因为我的变色龙模板宏结构是恶意的。