This is a migrated thread and some comments may be shown as answers.

spreadsheet relies on en-US months only for dates in Dynamicfilter

3 Answers 59 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 10 Jan 2017, 07:21 PM
I'm using the componentized version of KendoUI (v2016.3.1028) and I ran across a few oddities. The first being that the spreadsheet component appears to only use the en-US culture for the DynamicFilter property. Looking at kendo.web.js, there is this code block (see line 1 below):
1.kendo.cultures['en-US'].calendar.months.names.forEach(function (month, index) {
2.    kendo.spreadsheet.DynamicFilter.prototype[month.toLowerCase()] = function (value) {
3.        if (value instanceof Date) {
4.            return value.getMonth() === index;
5.        }
6.        return false;
7.    };
8.});

There doesn't appear to be a culture property that can be set on the spreadsheet kendo config, so I was curious if it's possible to even adjust the culture for the dates in the DynamicFilter to better respect localization?

 

Secondly, we include a number of culture localization files with our kendo.datpicker.js component so we can internationalize the text for datepicker usages. Unfotunately, adding the en-US culture to the datepicker becomes a problem for the spreadsheet which takes a dependency on datepicker. Looking at the code below from kendo.core.js, you can see that there is a function (called on file load) which will take in a culture (line 13 shows it's invoked with en-US) and add the calendar property to that particular culture. This calendar property is only used by the spreadsheet component, which assumes en-US, likely because this kendo.core.js only does this for en-US. It appears that the work-around would be to simply have the spreadsheet use the calendar's.standard property instead of assuming the kendo.cultures dictionary won't be updated between kendo.core.js load and the load of the kendo.web.js for spreadsheets. This could be achieved by exposing a property on spreadsheet for datePickerCulture which falls back to en-US by default. In any case, this is what drives the DynamicFilter property code for the spreadsheet and when we load a new culture for en-US, we lose the calendar property. We've worked around this by loading the culture files for the localizations we want, calling kendo.culture('en-US') to get the calendar property, then loading the kendo.spreadsheet.js with it's dependencies. Is this the right approach, or am I missing some instructions?

01.kendo.culture = function (cultureName) {
02.    var cultures = kendo.cultures, culture;
03.    if (cultureName !== undefined) {
04.        culture = findCulture(cultureName) || cultures[EN];
05.        culture.calendar = culture.calendars.standard;
06.        cultures.current = culture;
07.    } else {
08.        return cultures.current;
09.    }
10.};
11.kendo.findCulture = findCulture;
12.kendo.getCulture = getCulture;
13.kendo.culture(EN);

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 12 Jan 2017, 03:01 PM
Hello Stephen,

Regarding the questions:

1) Indeed, the implementation is made only for the 'en-US' culture. I can suggest using the same logic after the scripts are loaded and set the desired culture:

kendo.cultures['desired culture'].calendar.months.names.forEach(function (month, index) {
    kendo.spreadsheet.DynamicFilter.prototype[month.toLowerCase()] = function (value) {
        if (value instanceof Date) {
            return value.getMonth() === index;
        }
        return false;
    };
});

Also, sending us a pull request for this functionality will be highly appreciated:

https://github.com/telerik/kendo-ui-core/blob/master/CONTRIBUTING.md#3-submit-a-pull-request

2) I do believe that the second issue is related to the first one. I reviewed the code of the Spreadsheet and in all places kendo.cultures.calendar.standard instance is used. Also, the only DtePicker that is initialized is in the filter menu, but it will use the current active culture (defined with kendo.culture() globally).
That being said, the only place that kendo.culture().calendar is used is the aforementioned code snippet. As I mentioned, this is the intended behaviour, because the translations should be provided with separate (messages) files. The Spreadsheet widget is designed and work with only one global culture, defined with kendo.culture(). If you would like to change culture dynamically, then please recreate the spreadsheet.

I hope this will help to achieve the desired result.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Stephen
Top achievements
Rank 1
answered on 12 Jan 2017, 03:56 PM

Thank you for the reply Stefan,

To your points:

1) That's what we do to some degree, but I was curious if there was an alternative. It sounds like I would need to build that alternative, at least for now. Thank you for the code snippet to help us.

2) Globally changing kendo.culture() should work for us (we don't dynamically change culture), but I think I'm more curious why some components, like DatePicker (http://docs.telerik.com/kendo-ui/api/javascript/ui/datepicker#configuration-culture), have the ability to set culture directly on the configuration while others rely on the global kendo.culture()?

0
Stefan
Telerik team
answered on 16 Jan 2017, 10:09 AM
Hello Stephen,

Regarding the points:

1) I'm glad to hear that the suggestion was helpful. Indeed, this approach should be manually implemented.

2) The reason why the DatePicker or other form controls have specific culture options is because there are different valid scenarios, where one form or page can have the time or the numbers shown in a different culture when converting is used. For example, in converting currency where the two NumericTextBoxes can have different cultures. The container controls like the Grid or the Spreadsheet does not have this option as there are not some many scenarios where there are two Spreadsheets on the page with different cultures. Also, the containers widget have custom editors inside of them which can create culture conflicts.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Spreadsheet
Asked by
Stephen
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or