Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple example #6

Closed
yudao opened this issue Dec 23, 2013 · 3 comments
Closed

A simple example #6

yudao opened this issue Dec 23, 2013 · 3 comments

Comments

@yudao
Copy link

yudao commented Dec 23, 2013

Hi,

Firstly, thanks to the work accomplished.

I'm trying to test your API and it's difficult to understand how to load JSON data.

In fact, I've downloaded the generated JSON files (http://www.unicode.org/repos/cldr-aux/json/24/), put in a directory called "cldr" in my public directory.

There, I'm trying to implements some of your examples, like:

cldrLang = new Cldr("pt_BR")
console.log cldrLang.supplemental.minDays

But my first question is how we can tell to cldr runtime script to get the JSON files in the right directory?

I prefer to inform you that I'm using Node + Brunch + Bower.

Thanks a lot.

@rxaviers
Copy link
Owner

Hi @yudao,

Thanks for your interest. Good question. Basically, it's this:

Example of embedding CLDR JSON data:

<script>
Cldr.load({
  main: {
    en: {
      ...
    }
  },
  supplemental: {
    likelySubtags: {
      ...
    },
    timeDate: {
      ...
    },
    weekData: {
      ...
    }
  }
});
</script>

Example of loading it dynamically:

<script src="jquery.js"></script>
<script>
$.get( "cldr/en/ca-gregorian.json", Globalize.load );
$.get( "cldr/supplemental/likelySubtags.json", Globalize.load );
$.get( "cldr/supplemental/timeData.json", Globalize.load );
$.get( "cldr/supplemental/weekData.json", Globalize.load );
</script>

Example on AMD: (also see our functional tests)

define([
  "cldr",
  "json!fixtures/cldr/main/en/ca-gregorian.json",
  "json!fixtures/cldr/supplemental/likelySubtags.json",
  "json!fixtures/cldr/supplemental/timeData.json",
  "json!fixtures/cldr/supplemental/weekData.json"
], function( Cldr, enCaGregorian, likelySubtags, timeData, weekData ) {

  Cldr.load( enCaGregorian );
  Cldr.load( likelySubtags );
  Cldr.load( timeData );
  Cldr.load( weekData );

});

Example on node.js:

var Cldr = require( "cldr" );
Cldr.load( require("./cldr/supplemental/likelySubtags.json") );
Cldr.load( require("./cldr/supplemental/timeData.json") );
Cldr.load( require("./cldr/supplemental/weekData.json") );
Cldr.load( require("./cldr/en/ca-gregorian.json") );

Note that cldr does not fetch the data for you. But, you can use any other method to accomplish that, then feed Cldr.

Please, just let me know in any questions.

Action item:

  • This is something I need to improve in cldr's README as well.

@yudao
Copy link
Author

yudao commented Dec 24, 2013

Thanks a lot @rxaviers!

@yudao yudao closed this as completed Dec 24, 2013
@rxaviers
Copy link
Owner

You're welcome! I will leave this opened until README is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants