How to locale web2py date calendar widget

933 views
Skip to first unread message

Alexandre Andrade

unread,
Dec 23, 2009, 8:29:15 AM12/23/09
to web2py
While

db.convenio.data_assinatura.requires = IS_DATE(format=T('%d-%m-%Y'),error_message=T('deve ser no formato DD-MM-AAAA!'))

show me the date in correct locale, the calendar widget don't show the correct date.

How to locale it or  make it show the correct date?



--
Atenciosamente

--
=========================
Alexandre Andrade
Hipercenter.com

Brian M

unread,
Dec 23, 2009, 9:39:10 AM12/23/09
to web2py-users
I think that the format is controlled in the web2py_ajax.html view.

try {jQuery("input.date").focus( function() {Calendar.setup({
inputField:this.id, ifFormat:"{{=T('%Y-%m-%d')}}",
showsTime:false
}); }); } catch(e) {};
try { jQuery("input.datetime").focus( function() {Calendar.setup({
inputField:this.id, ifFormat:"{{=T('%Y-%m-%d %H:%M:%S')}}",
showsTime: true,timeFormat: "24"
}); }); } catch(e) {};

Since the format string seems to be in a T() I would guess that it's
possible to change that using translations?

~Brian

On Dec 23, 7:29 am, Alexandre Andrade <alexandrema...@gmail.com>
wrote:

Mengu

unread,
Dec 23, 2009, 7:54:28 PM12/23/09
to web2py-users
And note that yyyy-mm-dd format is the way how mysql and sqlite keep
dates.

Brian M

unread,
Dec 23, 2009, 9:24:02 PM12/23/09
to web2py-users
Mengu's right. While changing the format in web2py_ajax would make the
chosen date display in the format you wanted, upon submission the form
will be rejected because web2py wants only yyyy-mm-dd format. So if
you go that route you'd have to do some form processing yourself to
convert formats and probably not use SQLFORM.

Perhaps you could add an extra field that would be updated every time
the chosen date changed and have that field be in the correct format?
I know that jQuery UI's datepicker has an altField option built-in,
but I don't think the DynarchCalendar that web2py uses does. Maybe you
could create a widget that would use the jQuery UI calendar instead?

~Brian

mdipierro

unread,
Dec 23, 2009, 10:01:21 PM12/23/09
to web2py-users
the IS_DATE and IS_DATETIME accept a format argument. You should set
it explicitly

db.table.field.requires=IS_DATE(format=T('%Y-%M-%D'))

then use the translation interface to translate both the string above
and the calendar.js translation string.

Massimo

Álvaro Justen [Turicas]

unread,
Dec 26, 2009, 10:37:14 AM12/26/09
to web...@googlegroups.com
On Wed, Dec 23, 2009 at 11:29, Alexandre Andrade
<alexand...@gmail.com> wrote:
> While
>
> db.convenio.data_assinatura.requires =
> IS_DATE(format=T('%d-%m-%Y'),error_message=T('deve ser no formato
> DD-MM-AAAA!'))
>
> show me the date in correct locale, the calendar widget don't show the
> correct date.
>
> How to locale it or  make it show the correct date?

About calendar and other JS I think we need to have calendar_pt-BR.js,
calendar_en-ES.js etc.
I don't think T() is the best solution to translate static files. I
think it should be static and user should download
app/static/filename_LANG.js
So, we'll need to mantain many versions of the same file, but I think
it'll be nice for developers (calendar and other JS files being
translated automatically based on user accept-language). What do you
think?


> --
> Atenciosamente
>
> --
> =========================
> Alexandre Andrade
> Hipercenter.com
>

> --
>
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to
> web2py+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/web2py?hl=en.
>

--
Álvaro Justen
Peta5 - Nós fazemos TV digital
http://www.peta5.com.br/
21. 3021-6001 / 9898-0141

Thadeus Burgess

unread,
Dec 26, 2009, 5:16:56 PM12/26/09
to web...@googlegroups.com
How does jquery handle translations?

-Thadeus

mdipierro

unread,
Dec 26, 2009, 5:39:30 PM12/26/09
to web2py-users
I do not know. web2py should hanlde transaltions. You pass {{=T(...)}}
strings to jquery.

On Dec 26, 4:16 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> How does jquery handle translations?
>
> -Thadeus
>
> On Sat, Dec 26, 2009 at 9:37 AM, Álvaro Justen [Turicas]
>

Alexandre Andrade

unread,
Dec 26, 2009, 6:26:58 PM12/26/09
to web...@googlegroups.com
I will have to look to jquery code of widget to judge the best strategy, but I think  is a good alternative, specially because the translations need be done only once.



2009/12/26 Álvaro Justen [Turicas] <alvaro...@gmail.com>

Thadeus Burgess

unread,
Dec 26, 2009, 7:07:56 PM12/26/09
to web...@googlegroups.com
Agreed that web2py still should handle translations. I'm not sure but
for the purpose of this discussion, I think those who this concerns
should look at how javascript jquery programs perform translation and
see if there is a way either A) integrate web2py into this, or B) pass
web2py T() to these plugins....

We need to keep translation simple, so having a couple different
methods (one for web2py, one for javascript) probably isn't a good
idea.

-Thadeus

Álvaro Justen [Turicas]

unread,
Dec 26, 2009, 8:22:43 PM12/26/09
to web...@googlegroups.com
On Sat, Dec 26, 2009 at 22:07, Thadeus Burgess <thad...@thadeusb.com> wrote:
> Agreed that web2py still should handle translations. I'm not sure but
> for the purpose of this discussion, I think those who this concerns
> should look at how javascript jquery programs perform translation and
> see if there is a way either A) integrate web2py into this, or B) pass
> web2py T() to these plugins....
>
> We need to keep translation simple, so having a couple different
> methods (one for web2py, one for javascript) probably isn't a good
> idea.

We could create a Python/web2py script to translate the calendar
strings, creating one file for each language
(calendar_LANG_CODE-COUNTRY_CODE.js). and so use the script when a new
version of calendar is released. I don't think we should use T() for
this and I enforce this: this file should be static, we don't need to
handle these requests in a "dynamic" webserver.

Alexandre Andrade

unread,
Dec 28, 2009, 11:52:42 AM12/28/09
to web...@googlegroups.com
about calendar.js, I found in http://docs.jquery.com/Plugins/Calendar

that it has renamed to http://docs.jquery.com/UI/Datepicker.

Datepicker suports localization:
------------------------------------------------------------------------------------------------------------------------------

Localization

Datepicker provides support for localizing its content to cater for different languages and date formats. Each localization is contained within its own file with the language code appended to the name, e.g. jquery.ui.datepicker-fr.js for French. These files are loaded after the main datepicker code. They add their settings to the set of available localizations and automatically apply them as defaults for all instances.

The $.datepicker.regional attribute holds an array of localizations, indexed by language code, with '' referring to the default (English). Each entry is an object with the following attributes: closeText, prevText, nextText, currentText, monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, weekHeader, dateFormat, firstDay, isRTL, showMonthAfterYear, and yearSuffix.

You can restore the default localizations with:

$.datepicker.setDefaults($.datepicker.regional['']);

And can then override an individual datepicker for a specific locale:

$(selector).datepicker($.datepicker.regional['fr']);

The localization files are also available in the UI svn: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/

---------------------------------------------------------


Massimo, can you think about replace the calendar class in web2py?

or, If I am wrong, where find the docs about the calendar.js?



2009/12/24 mdipierro <mdip...@cs.depaul.edu>
--

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.



---------------

mdipierro

unread,
Dec 28, 2009, 12:24:37 PM12/28/09
to web2py-users
I am all for replacing the current calendar.js with another datepicker
but it must have datetimepicker functionality too. The one you propose
does not.

We could use this http://plugins.jquery.com/project/DateTimepicker but
I have not tried it.

I would take a patch to replace it.

Massimo

On Dec 28, 10:52 am, Alexandre Andrade <alexandrema...@gmail.com>
wrote:
> about calendar.js, I found inhttp://docs.jquery.com/Plugins/Calendar
>
> that it has renamed tohttp://docs.jquery.com/UI/Datepicker.


>
> Datepicker suports localization:
> ------------------------------------------------------------------------------------------------------------------------------
> Localization
>
> Datepicker provides support for localizing its content to cater for
> different languages and date formats. Each localization is contained within
> its own file with the language code appended to the name, e.g.
> jquery.ui.datepicker-fr.js for French. These files are loaded after the main
> datepicker code. They add their settings to the set of available
> localizations and automatically apply them as defaults for all instances.
>
> The $.datepicker.regional attribute holds an array of localizations, indexed
> by language code, with '' referring to the default (English). Each entry is
> an object with the following attributes: closeText, prevText, nextText,
> currentText, monthNames, monthNamesShort, dayNames, dayNamesShort,
> dayNamesMin, weekHeader, dateFormat, firstDay, isRTL, showMonthAfterYear,
> and yearSuffix.
>
> You can restore the default localizations with:
>
> $.datepicker.setDefaults($.datepicker.regional['']);
>
> And can then override an individual datepicker for a specific locale:
>
> $(selector).datepicker($.datepicker.regional['fr']);
> The localization files are also available in the UI svn:http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/
>
> ---------------------------------------------------------
>
> Massimo, can you think about replace the calendar class in web2py?
>
> or, If I am wrong, where find the docs about the calendar.js?
>

> 2009/12/24 mdipierro <mdipie...@cs.depaul.edu>

> > web2py+un...@googlegroups.com<web2py%2Bunsu...@googlegroups.com>

Brian M

unread,
Dec 28, 2009, 2:37:21 PM12/28/09
to web2py-users

mdipierro

unread,
Dec 28, 2009, 6:22:54 PM12/28/09
to web2py-users
I like it. Just make sure that if it is very fancy works cross
browser.

On Dec 28, 1:37 pm, Brian M <bmere...@gmail.com> wrote:
> How abouthttp://milesich.com/timepicker/

Stefan

unread,
Feb 12, 2010, 2:16:55 PM2/12/10
to web2py-users
I've been poking around the documentation for the jQuery datepicker
and I can't seem to find an answer to a question of mine. Is there any
way to limit the the choices that a user can make in the current
datepicker? Anotherwords, block out / allow certain days?

Thanks!

On Dec 28 2009, 6:22 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I like it. Just make sure that if it is very fancy works cross
> browser.
>
> On Dec 28, 1:37 pm, Brian M <bmere...@gmail.com> wrote:
>
>
>
> > How abouthttp://milesich.com/timepicker/
>
> > On Dec 28, 11:24 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>

> > > I am all for replacing the currentcalendar.js with another datepicker


> > > but it must have datetimepicker functionality too. The one you propose
> > > does not.
>
> > > We could use thishttp://plugins.jquery.com/project/DateTimepickerbut
> > > I have not tried it.
>
> > > I would take a patch to replace it.
>
> > > Massimo
>
> > > On Dec 28, 10:52 am, Alexandre Andrade <alexandrema...@gmail.com>
> > > wrote:
>

> > > > aboutcalendar.js, I found inhttp://docs.jquery.com/Plugins/Calendar


>
> > > > that it has renamed tohttp://docs.jquery.com/UI/Datepicker.
>
> > > > Datepicker suports localization:
> > > > --------------------------------------------------------------------------- ---------------------------------------------------
> > > > Localization
>
> > > > Datepicker provides support for localizing its content to cater for
> > > > different languages and date formats. Each localization is contained within
> > > > its own file with the language code appended to the name, e.g.
> > > >jquery.ui.datepicker-fr.js for French. These files are loaded after the main
> > > > datepicker code. They add their settings to the set of available
> > > > localizations and automatically apply them as defaults for all instances.
>
> > > > The $.datepicker.regional attribute holds an array of localizations, indexed
> > > > by language code, with '' referring to the default (English). Each entry is
> > > > an object with the following attributes: closeText, prevText, nextText,
> > > > currentText, monthNames, monthNamesShort, dayNames, dayNamesShort,
> > > > dayNamesMin, weekHeader, dateFormat, firstDay, isRTL, showMonthAfterYear,
> > > > and yearSuffix.
>
> > > > You can restore the default localizations with:
>
> > > > $.datepicker.setDefaults($.datepicker.regional['']);
>
> > > > And can then override an individual datepicker for a specific locale:
>
> > > > $(selector).datepicker($.datepicker.regional['fr']);
> > > > The localization files are also available in the UI svn:http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/
>
> > > > ---------------------------------------------------------
>

> > > > Massimo, can you think about replace thecalendarclass in web2py?


>
> > > > or, If I am wrong, where find the docs about thecalendar.js?
>
> > > > 2009/12/24 mdipierro <mdipie...@cs.depaul.edu>
>
> > > > > the IS_DATE and IS_DATETIME accept a format argument. You should set
> > > > > it explicitly
>
> > > > > db.table.field.requires=IS_DATE(format=T('%Y-%M-%D'))
>
> > > > > then use the translation interface to translate both the string above

> > > > > and thecalendar.js translation string.


>
> > > > > Massimo
>
> > > > > On Dec 23, 8:24 pm, Brian M <bmere...@gmail.com> wrote:
> > > > > > Mengu's right. While changing the format in web2py_ajax would make the
> > > > > > chosen date display in the format you wanted, upon submission the form
> > > > > > will be rejected because web2py wants only yyyy-mm-dd format. So if
> > > > > > you go that route you'd have to do some form processing yourself to
> > > > > > convert formats and probably not use SQLFORM.
>
> > > > > > Perhaps you could add an extra field that would be updated every time
> > > > > > the chosen date changed and have that field be in the correct format?

> > > > > > I know thatjQueryUI's datepicker has an altField option built-in,

> > > > > > > > > show me the date in correct locale, thecalendarwidget don't show

Reply all
Reply to author
Forward
0 new messages