Pyramid documentation shows us how to use i18n inside views (and templates as well). But how to does one use it outside of views and templates where we have no access to current request
(for example, in forms
and models
)?
@Michael said to pass request
to models and forms. But is it right? I mean if form fields defines before __init__()
method calls, the same with models. They don't see any parameters from views...
In Pylons we could simply use get_lang()
and set_lang()
and define preferable language in parent controller and then use ugettext()
and ungettext()
in any place we want without calling it from request
directly every possible time (in views).
How to do that in Pyramid? Note that the language must be set from user's settings (session, cookies, db, etc).