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

Culture ignored when loaded from requirejs

4 Answers 132 Views
Globalization
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 2
Alex asked on 31 Jul 2013, 02:15 AM
Hi,

In my root module (defined below), I call kendo.culture and it sets the culture right.
(function () {
    define(['jquery', 'amplify', 'modules/tools', 'k/kendo.router.min', 'k/kendo.view.min',
            'k/cultures/kendo.culture.fr-CA.min', 'k/cultures/kendo.culture.en-CA.min'], function ($, amplify, tools) {
1. I noticed that the culture that I set in my root module (app.js) does not propagate to other modules. Any idea why?

2. When I call kendo.culture in another module (to work around problem 1), the culture does not change (I check it by calling kendo.culture() from the console, it is always en-US. Any idea? Here is an example of how my other modules are defined (it's pretty much the same than above):

(function () {
    define(['jquery', 'amplify', 'modules/tools', 'modules/date', 'k/kendo.dataviz',
        'k/cultures/kendo.culture.fr-CA.min', 'k/cultures/kendo.culture.en-CA.min'], function ($, amplify, tools) {

Thanks,

Alex

4 Answers, 1 is accepted

Sort by
0
Mihai
Telerik team
answered on 31 Jul 2013, 02:48 PM

Hi,

Are there any errors in the JS console?  Particularly if you find any syntax
errors, please download a new build of Kendo UI and try again (there was a
known breakage between July 26-29, it has since been fixed).

If this doesn't fix the issue, it could be related to the order in which
your modules are loaded by RequireJS.  For example, if module X is loaded
before "app.js" and only in "app.js" you set the culture, then it's
possible that for a short while module X will only see the default culture.
The solution would be to declare to RequireJS that module X depends on
"app.js" (or if this isn't possible, move the setting of the culture in some
other module and make X depend on it).

Hope this helps. 

Best,
Mihai
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alex
Top achievements
Rank 2
answered on 01 Aug 2013, 06:48 PM
Hi,

There isn't any javascript error in the console, and I am sure that app.js is loaded before the other modules since it is the one who's responsible for actually loading them.

How does kendo.culture(something) behaves when it is encapsulated in a module? Does it affect a global variable? Could it be overwritten somehow?

Regards,

Alex
0
Alex
Top achievements
Rank 2
answered on 02 Aug 2013, 02:37 AM
I did a little bit more tests today, and I made the following observations:

In the second module to load, the one that has its culture reset to en-US:

1. Removing the cultures from the required modules in the define changes nothing
2. Changing k/kendo.dataviz to k/kendo.dataviz.min changes nothing
3. Removing k/kendo.dataviz.min from the required modules completely (there isn't any kendo modules left in the define) fixes the problem - the culture that was set earlier stays when I enter this module. It looks like something overwrites/breaks the culture in kendo.dataviz?

I hope it helps.

Alexis
0
Mihai
Telerik team
answered on 02 Aug 2013, 09:24 AM
Hi,

I attached a test case that shows the problem.  It's not related to kendo.dataviz but rather to the order in which RequireJS loads your files.  To test it you'll have to update paths to kendo and the stylesheets.

There are two scripts there, required from the test.html page: t1.js and t2.js.  In my tests it happens consistently that t2 executes before t1.  Each displays a calendar, but in t1.js I'm setting the culture to "fr-CA".  Because t2 happens before t1, you'll see the second calendar in English and the first one in French.  However, as soon as you change the month in the second calendar it'll display in French, since "t1" has finished loading and the global culture is now fr-CA.

Also take a look at the JS console, it should print "t2" and "t1".

The solution is to make "t2" depend on "t1" (which sets the culture).  Otherwise, RequireJS is free to load them in whatever order.

I placed commented code in "t2" with the fix, so you can see it works even though it includes "kendo.dataviz" as well.

Regards,
Mihai
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Globalization
Asked by
Alex
Top achievements
Rank 2
Answers by
Mihai
Telerik team
Alex
Top achievements
Rank 2
Share this question
or