Culture ignored when loaded from requirejs

5 posts, 0 answers
  1. Alex
    Alex avatar
    27 posts
    Member since:
    Oct 2011

    Posted 30 Jul 2013 Link to this post

    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
  2. Mihai
    Admin
    Mihai avatar
    153 posts

    Posted 31 Jul 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Alex
    Alex avatar
    27 posts
    Member since:
    Oct 2011

    Posted 01 Aug 2013 Link to this post

    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
  5. Alex
    Alex avatar
    27 posts
    Member since:
    Oct 2011

    Posted 01 Aug 2013 Link to this post

    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
  6. Mihai
    Admin
    Mihai avatar
    153 posts

    Posted 02 Aug 2013 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready