[英]Activate Translation in Pyramids
我想在金字塔框架中激活我的翻譯。 因此,我添加了翻譯目錄並設置了本地協商程序,例如https://stackoverflow.com/a/11289565/2648872,並在http://docs.pylonsproject.org/docs/pyramid/zh-CN/latest/narr/中進行了描述i18n.html#default-locale-negotiator 。 另外,我的ini文件中設置了默認語言和可用語言,但是pyramid不接受我的翻譯。 我會錯過一些激活翻譯的東西嗎?
問候
托比亞斯
編輯 :
我的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
金字塔實際上找不到您的翻譯目錄。 根據文檔,您需要傳遞絕對目錄路徑或資產規范 。 我更喜歡資產規范,因為我也習慣於進行視圖配置。
config.add_translation_dirs('dbas:locale')
因為您正在應用與本地化相關的部署設置,所以您不需要用例的自定義語言環境協商程序。 在金字塔配置中禁用自定義語言環境協商程序。 依靠默認語言環境協商程序的金字塔實現 。
您只需要兩件事就可以激活翻譯 。 僅首先應用這兩個概念。
為了進行調試,您可以使用以下概念之一來手動設置區域設置 。 我真的很喜歡在查詢字符串中傳遞LOCALE值。 例如,訪問
http://my.application?_LOCALE_=de
解決了此問題,導致我的變色龍模板宏結構被惡意破壞了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.