On 1/18/06, Jorge Godoy <[EMAIL PROTECTED]> wrote:
>
> Kevin Dangoor <[EMAIL PROTECTED]> writes:
>
> > I wouldn't do that as written. You shouldn't change a class attribute
> > in __init__. You could change it to self.javascript...
>
> I didn't get it.

        CalendarDatePicker.javascript=[JSLink(static, "calendar.js"),
        549                                            JSLink(static,
"lang/calendar-%s.js" % lang),
        550                                            JSLink(static,
"calendar-setup.js")]
        551     

By setting CalendarDatePicker.javascript, you're changing the property
*for all instances* of CalendarDatePicker... not just the one you're
instantiating.

>
> > Should the language be assumed to be the same for each visitor and
> > each request? I don't think so, in which case setting that is not the
> > right solution. Widgets are stateless, which means that each request
> > uses the very same widget object. So, dynamic, per-request behavior
> > has to happen in the methods that get called on the widget during
> > request processing.
>
> It is not assumed to be the same.  Here's how I use it:
>
>         widgets.CalendarDatePicker(attrs = {'size':11, 'maxlength':10},
>                                    name = "contrato_assinatura",
>                                    format = _("%d/%m/%Y"),
>                                    button_text = _(u"Calendário"),
>                                    lang = _('pt-utf8'),
>                                    labeltext = _('Data de vencimento do 
> contrato')),
>
> So, the same way you can mark the format to be translated, you also can mark
> the 'lang' that will be used by the calendar.  It tries guessing with
> get_locale, but I believe that it will work only on rare cases.

Oh, I see. You can use _() as you do there, or use lazygettext to do
it at request time. That seems reasonable.

You should be aware, though, that your example above (if used in a
form declared outside your controller) will only process _('pt-utf8')
once, at instantiation time. It won't vary from request to request.

>
> > I'm going to give some thought to making widgets stateful (ie
> > instantiated per request) so that people don't get tripped up by that.
> > I'm not sure if I can do that without causing minor breakage to
> > existing widgets (but, I'll see!)
>
> I believe it will work the way it is since the locale is in the session or is
> obtained when the page is requested.

The locale is, but unless you use lazygettext you're running the _()
call at instantiation time and not at request time... that's the
tricky bit of business around using stateful objects in a
multithreaded web environment.

Kevin

Reply via email to