开发者

How to get Dutch locale in Dojo to work?

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"> 
    </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 , l开发者_运维问答ocale=nl-nl

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


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.


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.


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.


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();
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜