proteus
proteus

Reputation: 555

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 ?

Upvotes: 2

Views: 1547

Answers (1)

Rafael Xavier
Rafael Xavier

Reputation: 2889

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

Upvotes: 1

Related Questions