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 . Additionally the default and available language in my ini files are set, but pyramid wont accept my translations. Do i miss something for activating translations?
Greetings
Tobias
Edit :
Snippet of my 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:
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. Unfortunately in my_locale_negotiator, they are not readable :(
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. For example, visiting
http://my.application?_LOCALE_=de
解决了此问题,导致我的变色龙模板宏结构被恶意破坏了。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.