3

I am trying to setup jquery globalize using the js/json setup suggested (for date module), using a javascript example suggested here.
In this code I am trying to set it up and the use it to format the jquery-ui datepicker:

(function () {

$(function () {
    $.when(
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/supplemental/likelySubtags.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-numbers-modern-master/main/en/numbers.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/supplemental/numberingSystems.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-dates-modern-master/main/en/ca-gregorian.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-dates-full-master/main/en/timeZoneNames.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/supplemental/timeData.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/supplemental/weekData.json")
    ).then(function () {

        // Normalize $.get results, we only need the JSON, not the request statuses.
        return [].slice.apply(arguments, [0]).map(function (result) {
            return result[0];
        });

    }).then(Globalize.load).then(function () {

        var culture = "en";
        Globalize(culture);
        $("input.datepicker").datepicker({
            prevText: '<i class="fa fa-chevron-left"></i>',
            nextText: '<i class="fa fa-chevron-right"></i>',
            dateFormat: Globalize.dateFormatter({ date: "short" })
        });
    });
});})();  

And the error I get is

E_DEFAULT_LOCALE_NOT_DEFINED: Default locale has not been defined. in globalize.js @ line 105

What am I doing wrong?

Chris Tsavas
  • 33
  • 2
  • 5
  • Did you read this? https://github.com/jquery/globalize/blob/master/doc/error/e-default-locale-not-defined.md – defectus Sep 24 '15 at 06:07
  • Yes, I have already. I tried both "Globalize(culture)" and "Globalize.locale(culture)" but I get the same error. – Chris Tsavas Sep 24 '15 at 06:17

1 Answers1

5

I used same code and had same error. Instead of:

    var culture = "en";
    Globalize(culture);
    $("input.datepicker").datepicker({
        prevText: '<i class="fa fa-chevron-left"></i>',
        nextText: '<i class="fa fa-chevron-right"></i>',
        dateFormat: Globalize.dateFormatter({ date: "short" })
    });

I just had: Globalize.locale("en"); and that fixed it.

  • Make sure your function is called
  • Make sure all your json objects are fetched
srdex
  • 76
  • 3
  • People might find this helpful for the 1.* globalize version as some functions now have been replaced/removed.: https://github.com/jquery/globalize/blob/master/doc/migrating-from-0.x.md – Chris Tsavas Oct 24 '15 at 16:06
  • Yeap. `Globalize.locale("en")` sets the default locale for the static methods (i.e., `Globalize.`); and `var en = Globalize("en")` creates the instance for the instance methods (i.e., `en.`). – Rafael Xavier Dec 27 '15 at 22:37