简体   繁体   中英

crazy problems with globalize.js

Ive spent the best part of a day just trying to get date validation to work with globalize.js. its proving to be a nightmare for something that should be quite simple. After much searching I found that i needed these files included and in a specific order

 <script src="~/Scripts/globalize.js"></script> <script src="~/Scripts/globalize/message.js"></script> <script src="~/Scripts/globalize/number.js"></script> <script src="~/Scripts/globalize/plural.js"></script> <script src="~/Scripts/globalize/date.js"></script> <script src="~/Scripts/globalize/currency.js"></script> <script src="~/Scripts/globalize/relative-time.js"></script> <script src="~/Scripts/globalize/unit.js"></script>

So I ran my app and got this error

E_MISSING_CLDR: Missing required CLDR content supplemental/likelySubtags .

this json data isnt included, so i added the file manually and included this in my master layout page

 <script type="text/javascript"> $.get("Scripts/cldr/supplemental/likelySubtags.json", Cldr.load); </script>

but I still get the same error, can anyone help me out ? How can i simply get globalize.js to actually work ?

Getting started

npm install globalize cldr-data

Then

var Globalize = require( "globalize" );
Globalize.load( require( "cldr-data" ).entireSupplemental() );
Globalize.load( require( "cldr-data" ).entireMainFor( "en", "es" ) );

Globalize("en").formatDate(new Date());
// > "11/27/2015"

Globalize("es").formatDate(new Date());
// > "27/11/2015"

Do you wanna run it on browsers? What's your stack? If you're using webpack, see this Globalize App example using webpack

If you use a different stack, see other examples https://github.com/globalizejs/globalize/#examples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM