views:

377

answers:

4

I need to format a date into a Dutch locale (Netherlands, Dutch language) string. I found that dojo supports this, but I can't get it to work. I am a Javascript newbie. Don't underestimate my blissful ignorence.

EDITED

<html>
  <title>title</title>
    <body>
    <SCRIPT TYPE="text/javascript" SRC="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js"&gt; 
    </SCRIPT>

 <script type="text/javascript">
  dojo.require("dojo.date");
  dojo.require("dojo.date.locale");

  dojo.addOnLoad(function() {
      var d = new Date('2009/12/23');
      console.log(d, dojo, dojo.date);

      var dstr = dojo.date.locale.format(d, {locale:'nl-nl'});
      document.write(dstr);
  });


 </script>
</body>

Firebug slaps me with:

Bundle not found: gregorian in dojo.cldr , locale=nl-nl

(function(){var 1=null;if((1||(typeof ....setTimeout(dojo._loadInit,1000);}})();\n

+1  A: 

Your code would work if you were including dojo from a local URI. Cross domain requires are forced to be asynchronous. See this dojo forum post on the issue.

You can use dojo.addOnLoad to get around this issue:

dojo.require("dojo.date");
dojo.require("dojo.date.locale");

dojo.addOnLoad(function() {
    var d = new Date('2009/12/23');
    console.log(d, dojo, dojo.date);

    var dstr = dojo.date.locale.format(d, {locale:'nl-nl'});
    document.write(dstr);
});

However, it then complains about your locale bundle. But that's a whole other story.

Justin Johnson
I got this error earlier yes: "Bundle not found: gregorian in dojo.cldr , locale=nl-nl." Thanks so far! You didn't solve my problem completely, but you did get me ahead. +1
Felix Ogg
A: 

I got fed up with this. Coded it out in a DIY manner. Tough luck for dojo.

      function formatDutchDate(date) {
   monthnames = ['januari','februari','maart','april','mei','juni','juli','augustus','september','oktober','november','december'];
   monthname = monthnames[date.getMonth()];
   return date.getDate()+' '+monthname+' '+date.getFullYear();
  }
Felix Ogg
+3  A: 

Standard Dojo packages come with a selection of locales. You need to run a script to create the missing ones. See my instructions at the Dojo website: Built-in locales, adding locales with custom build:

  1. Run ANT build in dojo-src/util/buildscripts/cldr
  2. Run Dojo build with localeList parameter
  3. Specify djConfig.locale or add djConfig.extraLocale

Alternatively you can use Google CDN version where all the locals have been created already AND define djConfig.extraLocale.

Maine
+2  A: 

Felix, please give it another try. You must simply specify the locale(s) you wish to use on the page at bootstrap time, in the tag that includes dojo.js. Then, there's no need to mention it anywhere else, unless you wish to support multiple locales on a page with djConfig.extraLocale

<SCRIPT TYPE="text/javascript" SRC="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" djConfig="locale: 'nl'">

If you don't specify this, the locale defaults to navigator.language, which is the installed language of your browser. Leaving the "locale" argument off the format call is what you typically would want to do. Then it will just pick up the default for that page.

peller
Even though Maine gave the answer earlier, your post drove the ball home for me, being a novice and all... Thanks!
Felix Ogg