Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #556 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

CalendarDatePicker I18N and problem with calendar_lang & format

Reported by: godoy Owned by: anonymous
Priority: normal Milestone:
Component: TG Widgets Version:
Severity: major Keywords:
Cc:

Description

What is the correct way to grant that calendar_lang will have the correct value for each lang? I thought that using lazy_gettext would solve it, but this causes an Exception to be thrown. If I don't provide a value here then, for example, Brazilian Portuguese speakers will see the calendar in English instead of Portuguese.

This works:

    widgets.CalendarDatePicker(attrs = {'size':11, 'maxlength':10},
                               name = "contrato_assinatura",
                               format = lazy_gettext("%d/%m/%Y"),
                               button_text = lazy_gettext(u"Calendário"),
                               calendar_lang = "pt-utf8",
                               label = lazy_gettext('Data de assinatura do contrato'),
                               ),

but this doesn't:

    widgets.CalendarDatePicker(attrs = {'size':11, 'maxlength':10},
                               name = "contrato_assinatura",
                               format = lazy_gettext("%d/%m/%Y"),
                               button_text = lazy_gettext(u"Calendário"),
                               calendar_lang = lazy_gettext("pt-utf8"),
                               label = lazy_gettext('Data de assinatura do contrato'),
                               ),

I.e., if I add something to allow changing 'calendar_lang' based on the language the user will be seeing, then I get a traceback telling me that thread._local has no method 'request'.

Traceback (most recent call last):
  File "./start-siteamostras.py", line 24, in ?
    from siteamostras.controllers import Root
  File "/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/controllers.py", line 15, in ?
    from siteamostras.toxicologia import Toxicologia
  File "/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/toxicologia.py", line 25, in ?
    import analises
  File "/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/analises.py", line 15, in ?
    from siteamostras import segmentos
  File "/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/segmentos.py", line 27, in ?
    from siteamostras.formularios import grid_segmentos, formulario_segmentos
  File "/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/formularios.py", line 146, in ?
    label = lazy_gettext('Data de assinatura do contrato'),
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py", line 48, in widgetinit
    func(self, *args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/big_widgets.py", line 48, in __init__
    "calendar/lang/calendar-%s.js" % calendar_lang),
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 100, in __str__
    return str(self.eval())
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 94, in eval
    return self.func(*self.args, **self.kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 46, in gettext
    return gettext_f(key, locale, domain)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 55, in _gettext
    if locale is None:locale = get_locale()
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/utils.py", line 65, in get_locale
    locale = get_locale_f()
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/utils.py", line 78, in _get_locale
    locale = cherrypy.session.get(locale_key)
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/filters/sessionfilter.py", line 413, in __getattr__
    sess = cherrypy.request._session
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/__init__.py", line 42, in __getattr__
    childobject = getattr(serving, self.__attrname__)
AttributeError: 'thread._local' object has no attribute 'request'

Change History

comment:1 Changed 13 years ago by godoy

  • Summary changed from CalendarDatePicker I18N and problem with calendar_lang to CalendarDatePicker I18N and problem with calendar_lang & format

I don't know why but now that I restarted my application the 'format' attribute also started throwing an exception if used like above:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py", line 99, in _run
    self.main()
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py", line 247, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in default
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 198, in expose
    func, tg_format, html, fragment, *args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/database.py", line 193, in run_with_transaction
    retval = func(*args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 215, in _execute_func
    output = errorhandling.try_call(func, self, *args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/errorhandling.py", line 61, in try_call
    output = func(self, *args, **kw)
  File "/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/clientes.py", line 48, in default
    return self.clientes(None, add = True)
  File "<string>", line 3, in clientes
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 193, in expose
    output = _execute_func(self, func, tg_format, html, fragment,
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 220, in _execute_func
    return _process_output(tg_format, output, html, fragment)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 68, in _process_output
    fragment=fragment)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/view.py", line 60, in render
    return engine.render(info, format, fragment, template)
  File "/usr/lib/python2.4/site-packages/TurboKid-0.9.0-py2.4.egg/turbokid/kidsupport.py", line 136, in render
    return t.serialize(encoding=self.defaultencoding, output=format, fragment=fragment)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/__init__.py", line 236, in serialize
    return serializer.serialize(self, encoding, fragment)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/serialization.py", line 51, in serialize
    text = list(self.generate(stream, encoding, fragment))
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/serialization.py", line 327, in generate
    for ev, item in self.apply_filters(stream):
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/serialization.py", line 84, in balancing_filter
    for ev, item in stream:
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py", line 206, in _coalesce
    for ev, item in stream:
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py", line 21, in transform_filter
    for ev, item in apply_matches(stream, template, templates, apply_func):
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py", line 31, in apply_matches
    item = stream.expand()
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py", line 95, in expand
    for ev, item in self._iter:
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py", line 164, in _track
    for p in stream:
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py", line 206, in _coalesce
    for ev, item in stream:
  File "/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/templates/clientes.py", line 177, in _pull
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py", line 21, in transform_filter
    for ev, item in apply_matches(stream, template, templates, apply_func):
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py", line 25, in apply_matches
    for ev, item in stream:
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py", line 164, in _track
    for p in stream:
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py", line 206, in _coalesce
    for ev, item in stream:
  File "<string>", line 66, in _pull
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py", line 39, in lockwidget
    output = self.__class__.display(self, *args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py", line 163, in display
    value = self.adjust_value(value, convert)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py", line 149, in adjust_value
    value = self.validator.from_python(value)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/formencode/formencode/api.py", line 342, in from_python
    value = self._from_python(value, state)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/validators.py", line 44, in _from_python
    return value.strftime(self.format)
TypeError: strftime() argument 1 must be str, not lazystring

I was just thinking here, but isn't there any means to make this format string use what is used by turbogears.i18n.format.format_date()? Can't it be a call to something dynamic?

comment:2 Changed 13 years ago by michele

In 0.9a2 I introduced the LocalizableJSLink that automatically selects the right language file.

comment:3 Changed 13 years ago by godoy

How to use it? How should I upgrade my code to make it work? And how can I "translate" for other languages (i.e., select other JS)?

comment:4 Changed 13 years ago by michele

Give a try to a plain CalendarDatePicker?, it's totally automatic, just change your browser language.

comment:5 Changed 13 years ago by godoy

This rox! ;-) I've changed all my calendars excluding calendar_lang attributes and everything is working as expected. ;-)

Now, just one improvement needs to be done: specifying the format automatically (or allowing us to use a "_" in it, so that we can override the way dates are entered and shown here after selecting from the calendar). If this is done, then CalendarDatePicker? (and CalendarDateTimePicker?) will be fully automated and I18Nized. ;-) Cool! Really cool!

Thank you!

comment:6 Changed 13 years ago by godoy

  • Status changed from new to closed
  • Resolution set to fixed

Solved (except for the format ;-)).

Note: See TracTickets for help on using tickets.