<pedantic>
from pyramid.request import Request
from pyramid.i18n import get_localizer
class MyRequest(Request)
def translation_activate_language(self, culture):
if self._LOCALE_ == culture:
return self.localizer
self._LOCALE_ = culture
del self.localizer
return get_localizer(self)
would be better done in 1.3+ without subclassing request as
def translation_activate_language(request, culture):
if request._LOCALE_ == culture:
return request.localizer
request._LOCALE_ = culture
del request.localizer
return get_localizer(request)
config.set_request_property(translation_activate_language)
</pedantic>
On Sun, Apr 15, 2012 at 12:24 PM, Chris Lambacher
<[email protected]> wrote:
> Hi,
>
> There isn't the ability to do that built in that will do that, but the
> pieces are there for you to be able to do it (as I am and have been since
> version 1.0 or 1.1). Depending on the Libraries you are depending on and
> their level of integration to the Pyramid i18n machinery you may need to do
> more or less work.
>
> The default way to do things is to use a Localizer that has been negotiated
> from the current request using a configured locale
> negotiator: http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/i18n.html#using-a-localizer.
> If you were to do the simplest and most logical thing (to change the
> _LOCALE_ property of the request and run get_localizer again you wouldn't
> see a change since get_localizer again to get a new Localizer, you would get
> back the same Localizer from before since get_localizer assumes that the
> locale will not change in the middle of the request and remembers the
> Localizer it got before.
>
> You probably *could* create a function added to the request like:
>
> from pyramid.request import Request
> from pyramid.i18n import get_localizer
>
> class MyRequest(Request)
> def translation_activate_language(self, culture):
> if self._LOCALE_ == culture:
> return self.localizer
> self._LOCALE_ = culture
> del self.localizer
> return get_localizer(self)
>
> I don't know how future proof that code is and when I was deciding how to do
> things for my application I decided to use the Pyramid
> provided pyramid.i18n.make_localizer function
> <http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/api/i18n.html#pyramid.i18n.make_localizer>
> to create my own get_localizer function. Note that I am *not* monkey
> patching this in to pyramid.i18n, I just use it in my code and have the
> appropriate integration points for my form validation
> (FormEncode/pyramid_simpleform based), date parsing, date printing, number
> printing, etc.
>
> My get_localizer function handles the locale negotiation that I need and
> does appropriate caching for performance according to the way that my locale
> changes.
>
> -Chris
>
>
> On Sunday, April 15, 2012, Sharpek wrote:
>>
>> Welcome,
>>
>> I was wondering how to dynamicly change the actual language version in
>> the application. I would like to do something like this:
>>
>> 1. Request
>> 2. Part of code of my application
>> 3. Change of application language from EN to DE
>> 4. Generate content of application in DE language
>> 5. Change application language from DE to EN
>> 6. Response
>>
>> There is something like "translation.activate(language)" in Django,
>> but unfortunetly I could not find something like this in Pyramid
>> documentation
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pylons-discuss" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/pylons-discuss?hl=en.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.