1. #1
    Sencha User
    Join Date
    Jul 2007
    Posts
    30
    Vote Rating
    0
    undefined is on a distinguished road

      0  

    Default Date i18n (Internationalization) - Conert from anyLocale to English

    Date i18n (Internationalization) - Conert from anyLocale to English


    I have a date field in a form which is internationalized. On submit of the form the locale specific date format is submitted to the server, the server is configured to handle dates in english formats only and hence it throws an exception.

    Is there any easy way to convert the submit value of a DateField from anyLocale to english ??

    Tried adding a hidden field to the form and onBlur event of datefield getting the date and converting to english format. But as the locale specific date file is loaded unable to convert to english - Any help on this is also appreciated.

    OR

    Any better way to achieve the same ??

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,616
    Vote Rating
    327
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    This does sound like a nuisance and I can't think of an easy way to do it. Workarounds depend to some extent on how you're submitting the form.

    Doing it with a hidden field sounds like a sensible idea. Why can't you convert the date to 'English'? Surely you just need to hardcode the date format in a call to the format() method?

    Incidentally, there is no such thing as an English locale date format. The UK & US have different date formats and there's no shortage of other English speaking countries with their own date preferences.

  3. #3
    Sencha User
    Join Date
    Jul 2007
    Posts
    30
    Vote Rating
    0
    undefined is on a distinguished road

      0  

    Default


    By converting it to English I meant. Once the locale.js files get loaded for a particular language, if I am not mistaken, they override the Date objects properties of month names. So suppose I want the date format 'dd-MMM-YY' to get submitted to the backend the French date becomes '02-Juil-2011' and crashes in the backend.

    So my problem, once the french user selects the date '02-Juil-2011' and submits the form the same date should go as '02-Jul-2011' (this is what I meant by English date). Found a hack to do this.

    BUT

    Now I have another problem. Can someone please tell me if this is an ExtJS bug. The getValue() of the ExtJS.DateField returns the Date object for the date selected, which works very well for english locale but the same returns null for certain months under certain languages. Like the Date object returns null if the french locale is loaded and the user selects any date in DECEMBER.

    If someone can verify if this is actually a bug or give a solution for just the bug then my problem is solved.

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,616
    Vote Rating
    327
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Like the Date object returns null if the french locale is loaded and the user selects any date in DECEMBER.
    Works for me.

    Which ExtJS version? Which browsers have you tried? Could you post your datefield config and any other steps to reproduce?

  5. #5
    Sencha User
    Join Date
    Jul 2007
    Posts
    30
    Vote Rating
    0
    undefined is on a distinguished road

      0  

    Default


    Using Ext version 3.3.1 on Firefox 5. Tried modifications on the locale examples date field. Even that doesnt work. Following is my date field, copied from the example file itself. Added the on blur event.

    Code:
    var datefield = new Ext.FormPanel({
                    renderTo: 'datefield',
                    labelWidth: 100, // label settings here cascade unless overridden
                    frame: true,
                    title: 'Datepicker',
                    bodyStyle: 'padding:5px 5px 0',
                    width: 360,
                    defaults: {width: 220},
                    defaultType: 'datefield',
                    items: [{
                        fieldLabel: 'Date',
                        name: 'date',
                        format : 'd-M-Y',
                        onBlur : function() {
                            console.log(this.getValue());
                        }
                    }]
                });

  6. #6
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,616
    Vote Rating
    327
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    I don't have FF5 to hand. Could you try with other browsers?

  7. #7
    Sencha User
    Join Date
    Jul 2007
    Posts
    30
    Vote Rating
    0
    undefined is on a distinguished road

      0  

    Default


    IE 8 and Chrome 12 - same results :-(
    @skirtle : Which browser are you using ?

  8. #8
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,616
    Vote Rating
    327
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    OK, managed to reproduce it and did some digging with a debugger. In summary, there's a mistake in the French locale file. The object Date.monthNumbers is supposed to contain short month names, whereas in the 2 French locale files it uses long names.

    I suggest you file this as a bug if it hasn't already been reported. The same bug is present in ExtJS 4 so it'll need fixing there if nowhere else. In the meantime it should be easy enough for you to patch it.

Thread Participants: 1

Tags for this Thread