globalize-rpk 1.7.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +5 -0
- package/README.md +818 -0
- package/{globalize → dist/globalize}/currency.js +3 -3
- package/{globalize → dist/globalize}/date.js +3 -3
- package/{globalize → dist/globalize}/message.js +2 -2
- package/{globalize → dist/globalize}/number.js +3 -3
- package/{globalize → dist/globalize}/plural.js +3 -3
- package/{globalize → dist/globalize}/relative-time.js +3 -3
- package/{globalize → dist/globalize}/unit.js +0 -0
- package/dist/globalize-runtime/currency.js +183 -0
- package/dist/globalize-runtime/date.js +1657 -0
- package/dist/globalize-runtime/message.js +120 -0
- package/dist/globalize-runtime/number.js +919 -0
- package/dist/globalize-runtime/plural.js +90 -0
- package/dist/globalize-runtime/relative-time.js +120 -0
- package/dist/globalize-runtime/unit.js +132 -0
- package/{globalize → dist}/globalize-runtime.js +0 -0
- package/{globalize → dist}/globalize.js +2 -2
- package/{node-main.js → dist/node-main.js} +0 -0
- package/doc/api/core/constructor.md +28 -0
- package/doc/api/core/load.md +96 -0
- package/doc/api/core/locale.md +43 -0
- package/doc/api/currency/currency-formatter.md +196 -0
- package/doc/api/currency/currency-to-parts-formatter.md +117 -0
- package/doc/api/date/date-formatter.md +203 -0
- package/doc/api/date/date-parser.md +60 -0
- package/doc/api/date/date-to-parts-formatter.md +176 -0
- package/doc/api/date/load-iana-time-zone.md +29 -0
- package/doc/api/message/load-messages.md +105 -0
- package/doc/api/message/message-formatter.md +208 -0
- package/doc/api/number/number-formatter.md +202 -0
- package/doc/api/number/number-parser.md +130 -0
- package/doc/api/number/number-to-parts-formatter.md +140 -0
- package/doc/api/plural/plural-generator.md +84 -0
- package/doc/api/relative-time/relative-time-formatter.md +60 -0
- package/doc/api/unit/unit-formatter.md +72 -0
- package/doc/blog-post/2017-07-xx-1.3.0-announcement.md +177 -0
- package/doc/cldr.md +114 -0
- package/doc/error/e-default-locale-not-defined.md +9 -0
- package/doc/error/e-invalid-cldr.md +14 -0
- package/doc/error/e-invalid-par-type.md +12 -0
- package/doc/error/e-invalid-par-value.md +11 -0
- package/doc/error/e-missing-cldr.md +11 -0
- package/doc/error/e-missing-parameter.md +10 -0
- package/doc/error/e-missing-plural-module.md +9 -0
- package/doc/error/e-par-missing-key.md +11 -0
- package/doc/error/e-par-out-of-range.md +13 -0
- package/doc/error/e-unsupported.md +10 -0
- package/doc/migrating-from-0.x.md +64 -0
- package/examples/amd-bower/.bowerrc +7 -0
- package/examples/amd-bower/README.md +65 -0
- package/examples/amd-bower/bower.json +13 -0
- package/examples/amd-bower/index.html +46 -0
- package/examples/amd-bower/main.js +141 -0
- package/examples/amd-bower/messages/en.json +12 -0
- package/examples/amd-bower/package.json +14 -0
- package/examples/app-npm-webpack/README.md +74 -0
- package/examples/app-npm-webpack/app/index.js +89 -0
- package/examples/app-npm-webpack/index-template.html +71 -0
- package/examples/app-npm-webpack/messages/ar.json +25 -0
- package/examples/app-npm-webpack/messages/de.json +21 -0
- package/examples/app-npm-webpack/messages/en.json +21 -0
- package/examples/app-npm-webpack/messages/es.json +21 -0
- package/examples/app-npm-webpack/messages/pt.json +21 -0
- package/examples/app-npm-webpack/messages/ru.json +23 -0
- package/examples/app-npm-webpack/messages/zh.json +20 -0
- package/examples/app-npm-webpack/package.json +17 -0
- package/examples/app-npm-webpack/webpack-config.js +63 -0
- package/examples/globalize-compiler/README.md +45 -0
- package/examples/globalize-compiler/app.js +58 -0
- package/examples/globalize-compiler/development.html +121 -0
- package/examples/globalize-compiler/messages.json +12 -0
- package/examples/globalize-compiler/package.json +15 -0
- package/examples/globalize-compiler/production.html +75 -0
- package/examples/node-npm/README.md +57 -0
- package/examples/node-npm/main.js +65 -0
- package/examples/node-npm/messages/en.json +12 -0
- package/examples/node-npm/package.json +10 -0
- package/examples/plain-javascript/README.md +81 -0
- package/examples/plain-javascript/index.html +445 -0
- package/package.json +27 -4
@@ -0,0 +1,45 @@
|
|
1
|
+
# Basic Globalize Compiler example
|
2
|
+
|
3
|
+
This example focuses on the Globalize Compiler and the Globalize runtime
|
4
|
+
modules. It assumes knowledge of Globalize usage basics.
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
|
8
|
+
**1. Install Globalize dependencies and Globalize Compiler**
|
9
|
+
|
10
|
+
This example uses `npm` to download Globalize dependencies (i.e., CLDR data and
|
11
|
+
the Cldrjs library) and the [Globalize Compiler][].
|
12
|
+
|
13
|
+
```
|
14
|
+
npm install
|
15
|
+
```
|
16
|
+
|
17
|
+
[Globalize Compiler]: https://github.com/globalizejs/globalize-compiler
|
18
|
+
|
19
|
+
## Running the example
|
20
|
+
|
21
|
+
### Development mode
|
22
|
+
|
23
|
+
1. Start a server by running `python -m SimpleHTTPServer` or other alternative
|
24
|
+
servers such as [http-server][], [nginx][], [apache][].
|
25
|
+
1. Point your browser at `http://localhost:8000/development.html`. Note that the
|
26
|
+
formatters are created dynamically. Therefore, Cldrjs and CLDR data are
|
27
|
+
required.
|
28
|
+
1. Understand the demo by reading the source code. We have comments there for
|
29
|
+
you.
|
30
|
+
|
31
|
+
[http-server]: https://github.com/nodeapps/http-server
|
32
|
+
[nginx]: http://nginx.org/en/docs/
|
33
|
+
[apache]: http://httpd.apache.org/docs/trunk/
|
34
|
+
|
35
|
+
### Production mode
|
36
|
+
|
37
|
+
1. Compile the application formatters by running `npm run build`. See
|
38
|
+
`package.json` to understand the actual shell command that is used. For more
|
39
|
+
information about the compiler, see the [Globalize Compiler documentation][].
|
40
|
+
1. Point your browser at `./production.html`. Note that we don't need Cldrjs nor
|
41
|
+
CLDR data in production here.
|
42
|
+
1. Understand the demo by reading the source code. We have comments there for
|
43
|
+
you.
|
44
|
+
|
45
|
+
[Globalize Compiler documentation]: https://github.com/globalizejs/globalize-compiler#README
|
@@ -0,0 +1,58 @@
|
|
1
|
+
var like, number;
|
2
|
+
|
3
|
+
// Use Globalize to format dates.
|
4
|
+
document.getElementById( "date" ).textContent = Globalize.formatDate( new Date(), {
|
5
|
+
datetime: "medium"
|
6
|
+
});
|
7
|
+
|
8
|
+
// Use Globalize to format dates on specific time zone.
|
9
|
+
document.getElementById( "zonedDate" ).textContent = Globalize.formatDate( new Date(), {
|
10
|
+
datetime: "full",
|
11
|
+
timeZone: "America/Sao_Paulo"
|
12
|
+
});
|
13
|
+
|
14
|
+
// Use Globalize to format dates to parts.
|
15
|
+
document.getElementById( "dateToParts" ).innerHTML = Globalize.formatDateToParts( new Date(), {
|
16
|
+
datetime: "medium"
|
17
|
+
}).map(function( part ) {
|
18
|
+
switch(part.type) {
|
19
|
+
case "month": return "<strong>" + part.value + "</strong>";
|
20
|
+
default: return part.value;
|
21
|
+
}
|
22
|
+
}).reduce(function( memo, value ) {
|
23
|
+
return memo + value;
|
24
|
+
});
|
25
|
+
|
26
|
+
// Use Globalize to format numbers.
|
27
|
+
number = Globalize.numberFormatter();
|
28
|
+
document.getElementById( "number" ).textContent = number( 12345.6789 );
|
29
|
+
document.getElementById( "number-compact" ).textContent = Globalize.formatNumber( 12345.6789, {
|
30
|
+
compact: "short",
|
31
|
+
minimumSignificantDigits: 1,
|
32
|
+
maximumSignificantDigits: 3
|
33
|
+
});
|
34
|
+
|
35
|
+
// Use Globalize to format currencies.
|
36
|
+
document.getElementById( "currency" ).textContent = Globalize.formatCurrency( 69900, "USD" );
|
37
|
+
|
38
|
+
// Use Globalize to get the plural form of a numeric value.
|
39
|
+
document.getElementById( "plural-number" ).textContent = number( 12345.6789 );
|
40
|
+
document.getElementById( "plural-form" ).textContent = Globalize.plural( 12345.6789 );
|
41
|
+
|
42
|
+
// Use Globalize to format a message with plural inflection.
|
43
|
+
like = Globalize.messageFormatter( "like" );
|
44
|
+
document.getElementById( "message-0" ).textContent = like( 0 );
|
45
|
+
document.getElementById( "message-1" ).textContent = like( 1 );
|
46
|
+
document.getElementById( "message-2" ).textContent = like( 2 );
|
47
|
+
document.getElementById( "message-3" ).textContent = like( 3 );
|
48
|
+
|
49
|
+
// Use Globalize to format a relative time.
|
50
|
+
document.getElementById( "relative-time" ).textContent = Globalize.formatRelativeTime( -35, "second" );
|
51
|
+
|
52
|
+
// Use Globalize to format a unit.
|
53
|
+
document.getElementById( "unit" ).textContent = Globalize.formatUnit( 60, "mile/hour", {
|
54
|
+
form: "short"
|
55
|
+
});
|
56
|
+
|
57
|
+
document.getElementById( "requirements" ).style.display = "none";
|
58
|
+
document.getElementById( "demo" ).style.display = "block";
|
@@ -0,0 +1,121 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<head>
|
3
|
+
<meta charset="utf-8">
|
4
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
5
|
+
<title>Basic Globalize Compiler example (development mode)</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>Basic Globalize Compiler example (development mode)</h1>
|
9
|
+
|
10
|
+
<div id="requirements">
|
11
|
+
<h2>Requirements</h2>
|
12
|
+
<ul>
|
13
|
+
<li>Read README.md for instructions.</li>
|
14
|
+
</ul>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div id="demo" style="display: none">
|
18
|
+
<h2>Demo output</h2>
|
19
|
+
<p>Now: <span id="date"></span></p>
|
20
|
+
<p>Now: <span id="dateToParts"></span> (note the highlighted month, the markup was added using formatDateToParts)</p>
|
21
|
+
<p>Now (in America/Sao_Paulo): <span id="zonedDate"></span></p>
|
22
|
+
<p>A number: <span id="number"></span></p>
|
23
|
+
<p>A number (compact form): <span id="number-compact"></span></p>
|
24
|
+
<p>A currency: <span id="currency"></span></p>
|
25
|
+
<p>Plural form of <span id="plural-number"></span> is <span id="plural-form"></span></p>
|
26
|
+
<p>Messages:</p>
|
27
|
+
<ul>
|
28
|
+
<li><span id="message-0"></span></li>
|
29
|
+
<li><span id="message-1"></span></li>
|
30
|
+
<li><span id="message-2"></span></li>
|
31
|
+
<li><span id="message-3"></span></li>
|
32
|
+
</ul>
|
33
|
+
<p>Something happened: <span id="relative-time"></span></p>
|
34
|
+
<p>Speed limit: <span id="unit"></span></p>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<!--
|
38
|
+
First, we load Globalize's dependencies (`cldrjs` and its supplemental
|
39
|
+
module).
|
40
|
+
-->
|
41
|
+
<script src="node_modules/globalize/node_modules/cldrjs/dist/cldr.js"></script>
|
42
|
+
<script src="node_modules/globalize/node_modules/cldrjs/dist/cldr/event.js"></script>
|
43
|
+
<script src="node_modules/globalize/node_modules/cldrjs/dist/cldr/supplemental.js"></script>
|
44
|
+
<!--
|
45
|
+
npm@3 installs flat by default differently from npm@1 and npm@2, so either
|
46
|
+
the below or the above will work. Don't do this at your application, pick
|
47
|
+
one.
|
48
|
+
-->
|
49
|
+
<script src="node_modules/cldrjs/dist/cldr.js"></script>
|
50
|
+
<script src="node_modules/cldrjs/dist/cldr/event.js"></script>
|
51
|
+
<script src="node_modules/cldrjs/dist/cldr/supplemental.js"></script>
|
52
|
+
|
53
|
+
<!--
|
54
|
+
Next, we load Globalize and its modules. Note they are already available on
|
55
|
+
this repository. If it's not, read Usage on Getting Started on the root's
|
56
|
+
README.md.
|
57
|
+
-->
|
58
|
+
<script src="node_modules/globalize/dist/globalize.js"></script>
|
59
|
+
<script src="node_modules/globalize/dist/globalize/message.js"></script>
|
60
|
+
<script src="node_modules/globalize/dist/globalize/number.js"></script>
|
61
|
+
<script src="node_modules/globalize/dist/globalize/plural.js"></script>
|
62
|
+
|
63
|
+
<!-- Load after globalize/number.js -->
|
64
|
+
<script src="node_modules/globalize/dist/globalize/date.js"></script>
|
65
|
+
<script src="node_modules/globalize/dist/globalize/currency.js"></script>
|
66
|
+
|
67
|
+
<!-- Load after globalize/number.js and globalize/plural.js-->
|
68
|
+
<script src="node_modules/globalize/dist/globalize/relative-time.js"></script>
|
69
|
+
<script src="node_modules/globalize/dist/globalize/unit.js"></script>
|
70
|
+
|
71
|
+
<!-- Load jQuery to fetch the CLDR and message JSONs -->
|
72
|
+
<script src="node_modules/jquery/dist/jquery.js"></script>
|
73
|
+
|
74
|
+
<script>
|
75
|
+
|
76
|
+
// At this point, we have Globalize loaded. But, before we can use it, we
|
77
|
+
// need to feed it on the appropriate I18n content (Unicode CLDR). In order
|
78
|
+
// to do so, we use `Globalize.load()` and pass the content. On this demo,
|
79
|
+
// we made the things a little easier for you: we've embedded static JSON
|
80
|
+
// into the demo. So, you don't need to actually fetch it elsewhere.
|
81
|
+
$.when(
|
82
|
+
$.getJSON( "node_modules/cldr-data/main/en/ca-gregorian.json" ),
|
83
|
+
$.getJSON( "node_modules/cldr-data/main/en/currencies.json" ),
|
84
|
+
$.getJSON( "node_modules/cldr-data/main/en/dateFields.json" ),
|
85
|
+
$.getJSON( "node_modules/cldr-data/main/en/numbers.json" ),
|
86
|
+
$.getJSON( "node_modules/cldr-data/main/en/timeZoneNames.json" ),
|
87
|
+
$.getJSON( "node_modules/cldr-data/main/en/units.json" ),
|
88
|
+
$.getJSON( "node_modules/cldr-data/supplemental/currencyData.json" ),
|
89
|
+
$.getJSON( "node_modules/cldr-data/supplemental/likelySubtags.json" ),
|
90
|
+
$.getJSON( "node_modules/cldr-data/supplemental/metaZones.json" ),
|
91
|
+
$.getJSON( "node_modules/cldr-data/supplemental/plurals.json" ),
|
92
|
+
$.getJSON( "node_modules/cldr-data/supplemental/timeData.json" ),
|
93
|
+
$.getJSON( "node_modules/cldr-data/supplemental/weekData.json" ),
|
94
|
+
$.getJSON( "messages.json" ),
|
95
|
+
$.getJSON( "node_modules/iana-tz-data/iana-tz-data.json" )
|
96
|
+
).then(function( enCaGregorian, enCurrencies, enDateFields, enNumbers, enTimeZoneNames, enUnits,
|
97
|
+
currencyData, likelySubtags, metaZones, plurals, timeData, weekData, messages, ianaTzData ) {
|
98
|
+
|
99
|
+
Globalize.load( enCaGregorian[ 0 ] );
|
100
|
+
Globalize.load( enCurrencies[ 0 ] );
|
101
|
+
Globalize.load( enDateFields[ 0 ] );
|
102
|
+
Globalize.load( enNumbers[ 0 ] );
|
103
|
+
Globalize.load( enTimeZoneNames[ 0 ] );
|
104
|
+
Globalize.load( enUnits[ 0 ] );
|
105
|
+
Globalize.load( currencyData[ 0 ] );
|
106
|
+
Globalize.load( likelySubtags[ 0 ] );
|
107
|
+
Globalize.load( metaZones[ 0 ] );
|
108
|
+
Globalize.load( plurals[ 0 ] );
|
109
|
+
Globalize.load( timeData[ 0 ] );
|
110
|
+
Globalize.load( weekData[ 0 ] );
|
111
|
+
Globalize.loadMessages( messages[ 0 ] );
|
112
|
+
Globalize.loadTimeZone( ianaTzData[ 0 ] );
|
113
|
+
Globalize.locale("en");
|
114
|
+
|
115
|
+
// Load and execute our App.
|
116
|
+
$.getScript( "app.js" );
|
117
|
+
})
|
118
|
+
</script>
|
119
|
+
|
120
|
+
</body>
|
121
|
+
</html>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"name": "basic-globalize-compiler",
|
3
|
+
"private": true,
|
4
|
+
"scripts": {
|
5
|
+
"build": "globalize-compiler -l en -m messages.json -o compiled-formatters.js app.js"
|
6
|
+
},
|
7
|
+
"devDependencies": {
|
8
|
+
"cldr-data": ">=25",
|
9
|
+
"globalize": "^1.5.0",
|
10
|
+
"globalize-compiler": "^1.1.1",
|
11
|
+
"iana-tz-data": "^2017.1.0",
|
12
|
+
"jquery": "latest"
|
13
|
+
},
|
14
|
+
"cldr-data-urls-filter": "(core|dates|numbers|units)"
|
15
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<head>
|
3
|
+
<meta charset="utf-8">
|
4
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
5
|
+
<title>Basic Globalize Compiler example (production mode)</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>Basic Globalize Compiler example (production mode)</h1>
|
9
|
+
|
10
|
+
<div id="requirements">
|
11
|
+
<h2>Requirements</h2>
|
12
|
+
<ul>
|
13
|
+
<li>You need to build the `compiled-formatters.js`. Read README.md for instructions.
|
14
|
+
</li>
|
15
|
+
</ul>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div id="demo" style="display: none">
|
19
|
+
<h2>Demo output</h2>
|
20
|
+
<p>Now: <span id="date"></span></p>
|
21
|
+
<p>Now: <span id="dateToParts"></span> (note the highlighted month, the markup was added using formatDateToParts)</p>
|
22
|
+
<p>Now (in America/Sao_Paulo): <span id="zonedDate"></span></p>
|
23
|
+
<p>A number: <span id="number"></span></p>
|
24
|
+
<p>A number (compact form): <span id="number-compact"></span></p>
|
25
|
+
<p>A currency: <span id="currency"></span></p>
|
26
|
+
<p>Plural form of <span id="plural-number"></span> is <span id="plural-form"></span></p>
|
27
|
+
<p>Messages:</p>
|
28
|
+
<ul>
|
29
|
+
<li><span id="message-0"></span></li>
|
30
|
+
<li><span id="message-1"></span></li>
|
31
|
+
<li><span id="message-2"></span></li>
|
32
|
+
<li><span id="message-3"></span></li>
|
33
|
+
</ul>
|
34
|
+
<p>Something happened: <span id="relative-time"></span></p>
|
35
|
+
<p>Speed limit: <span id="unit"></span></p>
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<!--
|
39
|
+
Note, we don't need cldrjs library anymore because the formatters have
|
40
|
+
already been created by the compilation step. More info below.
|
41
|
+
-->
|
42
|
+
|
43
|
+
<!-- Load Globalize runtime and its runtime modules -->
|
44
|
+
<script src="node_modules/globalize/dist/globalize-runtime.js"></script>
|
45
|
+
<script src="node_modules/globalize/dist/globalize-runtime/message.js"></script>
|
46
|
+
<script src="node_modules/globalize/dist/globalize-runtime/number.js"></script>
|
47
|
+
<script src="node_modules/globalize/dist/globalize-runtime/plural.js"></script>
|
48
|
+
|
49
|
+
<!-- Load after globalize-runtime/number.js -->
|
50
|
+
<script src="node_modules/globalize/dist/globalize-runtime/date.js"></script>
|
51
|
+
<script src="node_modules/globalize/dist/globalize-runtime/currency.js"></script>
|
52
|
+
|
53
|
+
<!--
|
54
|
+
Load after globalize-runtime/number.js and globalize-runtime/plural.js
|
55
|
+
-->
|
56
|
+
<script src="node_modules/globalize/dist/globalize-runtime/relative-time.js"></script>
|
57
|
+
<script src="node_modules/globalize/dist/globalize-runtime/unit.js"></script>
|
58
|
+
|
59
|
+
<!--
|
60
|
+
Then, load the compiled formatters.
|
61
|
+
|
62
|
+
Note, we don't need to feed Globalize on CLDR data anymore because the
|
63
|
+
formatters have already been created by the compilation step and their
|
64
|
+
"snapshots" are available below.
|
65
|
+
-->
|
66
|
+
<script src="compiled-formatters.js"></script>
|
67
|
+
|
68
|
+
<!-- Our App -->
|
69
|
+
<script>
|
70
|
+
Globalize.locale("en");
|
71
|
+
</script>
|
72
|
+
<script src="app.js"></script>
|
73
|
+
|
74
|
+
</body>
|
75
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Hello World (Node.js + npm)
|
2
|
+
|
3
|
+
We assume you know what [Node.js](http://nodejs.org/) and
|
4
|
+
[npm](https://www.npmjs.org/) is.
|
5
|
+
|
6
|
+
The demo contains one single file:
|
7
|
+
|
8
|
+
```
|
9
|
+
.
|
10
|
+
└── main.js
|
11
|
+
```
|
12
|
+
|
13
|
+
Before running it, execute the requirements below.
|
14
|
+
|
15
|
+
|
16
|
+
## Requirements
|
17
|
+
|
18
|
+
**1. Install Globalize**
|
19
|
+
|
20
|
+
Let's use npm to download Globalize. For more information on regard of
|
21
|
+
installation, please read [Getting Started](../../README.md#installation).
|
22
|
+
|
23
|
+
```
|
24
|
+
npm install
|
25
|
+
```
|
26
|
+
|
27
|
+
Then, you'll get this:
|
28
|
+
|
29
|
+
```
|
30
|
+
.
|
31
|
+
├── node_modules/
|
32
|
+
│ ├── globalize/
|
33
|
+
│ │ └── dist/
|
34
|
+
│ │ ├── globalize
|
35
|
+
│ │ │ ├── date.js
|
36
|
+
│ │ │ └── ...
|
37
|
+
│ │ └── globalize.js
|
38
|
+
│ └── ...
|
39
|
+
└── main.js
|
40
|
+
```
|
41
|
+
|
42
|
+
**2. Dependencies**
|
43
|
+
|
44
|
+
No action needed, because npm has already handled that for us.
|
45
|
+
|
46
|
+
**3. CLDR content**
|
47
|
+
|
48
|
+
No action needed, because npm has already handled that for us. For more
|
49
|
+
information, see [npm's cldr-data](https://github.com/rxaviers/cldr-data-npm).
|
50
|
+
|
51
|
+
|
52
|
+
## Running the demo
|
53
|
+
|
54
|
+
Once you've completed the requirements above:
|
55
|
+
|
56
|
+
1. Run `node main.js`.
|
57
|
+
1. Understand the demo by reading the source code. We have comments there for you.
|
@@ -0,0 +1,65 @@
|
|
1
|
+
var like;
|
2
|
+
var Globalize = require( "globalize" );
|
3
|
+
|
4
|
+
// Before we can use Globalize, we need to feed it on the appropriate I18n content (Unicode CLDR). Read Requirements on Getting Started on the root's README.md for more information.
|
5
|
+
Globalize.load(
|
6
|
+
require( "cldr-data/main/en/ca-gregorian" ),
|
7
|
+
require( "cldr-data/main/en/currencies" ),
|
8
|
+
require( "cldr-data/main/en/dateFields" ),
|
9
|
+
require( "cldr-data/main/en/numbers" ),
|
10
|
+
require( "cldr-data/main/en/timeZoneNames" ),
|
11
|
+
require( "cldr-data/main/en/units" ),
|
12
|
+
require( "cldr-data/supplemental/currencyData" ),
|
13
|
+
require( "cldr-data/supplemental/likelySubtags" ),
|
14
|
+
require( "cldr-data/supplemental/metaZones" ),
|
15
|
+
require( "cldr-data/supplemental/plurals" ),
|
16
|
+
require( "cldr-data/supplemental/timeData" ),
|
17
|
+
require( "cldr-data/supplemental/weekData" )
|
18
|
+
);
|
19
|
+
Globalize.loadMessages( require( "./messages/en" ) );
|
20
|
+
|
21
|
+
Globalize.loadTimeZone( require( "iana-tz-data" ) );
|
22
|
+
|
23
|
+
// Set "en" as our default locale.
|
24
|
+
Globalize.locale( "en" );
|
25
|
+
|
26
|
+
// Use Globalize to format dates.
|
27
|
+
console.log( Globalize.formatDate( new Date(), { datetime: "medium" } ) );
|
28
|
+
|
29
|
+
// Use Globalize to format dates in specific time zones.
|
30
|
+
console.log( Globalize.formatDate( new Date(), {
|
31
|
+
datetime: "full",
|
32
|
+
timeZone: "America/Sao_Paulo"
|
33
|
+
}));
|
34
|
+
|
35
|
+
// Use Globalize to format dates to parts.
|
36
|
+
console.log( Globalize.formatDateToParts( new Date(), { datetime: "medium" } ) );
|
37
|
+
|
38
|
+
// Use Globalize to format numbers.
|
39
|
+
console.log( Globalize.formatNumber( 12345.6789 ) );
|
40
|
+
|
41
|
+
// Use Globalize to format numbers (compact form).
|
42
|
+
console.log( Globalize.formatNumber( 12345.6789, {
|
43
|
+
compact: "short",
|
44
|
+
minimumSignificantDigits: 1,
|
45
|
+
maximumSignificantDigits: 3
|
46
|
+
}));
|
47
|
+
|
48
|
+
// Use Globalize to format currencies.
|
49
|
+
console.log( Globalize.formatCurrency( 69900, "USD" ) );
|
50
|
+
|
51
|
+
// Use Globalize to get the plural form of a numeric value.
|
52
|
+
console.log( Globalize.plural( 12345.6789 ) );
|
53
|
+
|
54
|
+
// Use Globalize to format a message with plural inflection.
|
55
|
+
like = Globalize.messageFormatter( "like" );
|
56
|
+
console.log( like( 0 ) );
|
57
|
+
console.log( like( 1 ) );
|
58
|
+
console.log( like( 2 ) );
|
59
|
+
console.log( like( 3 ) );
|
60
|
+
|
61
|
+
// Use Globalize to format relative time.
|
62
|
+
console.log( Globalize.formatRelativeTime( -35, "second" ) );
|
63
|
+
|
64
|
+
// Use Globalize to format unit.
|
65
|
+
console.log( Globalize.formatUnit( 60, "mile/hour", { form: "short" } ) );
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Hello World (plain javascript)
|
2
|
+
|
3
|
+
The demo contains one single file:
|
4
|
+
|
5
|
+
```
|
6
|
+
.
|
7
|
+
└── index.html
|
8
|
+
```
|
9
|
+
|
10
|
+
Before running it, execute the requirements below.
|
11
|
+
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
|
15
|
+
**1. Dependencies**
|
16
|
+
|
17
|
+
The demo requires Globalize and its dependencies. Globalize's dependencies are listed on [Getting
|
18
|
+
Started](../../README.md#dependencies), and the only one is
|
19
|
+
[cldrjs](https://github.com/rxaviers/cldrjs). You are free to fetch it the way you want. But, as an
|
20
|
+
exercise of this demo, we'll download it ourselves. So:
|
21
|
+
|
22
|
+
1. Click at [Globalize releases tab](https://github.com/globalizejs/globalize/releases).
|
23
|
+
1. Download the latest package.
|
24
|
+
1. Unzip it.
|
25
|
+
1. Rename the extracted directory `globalize` and move it alongside `index.html` and `README.md`.
|
26
|
+
1. Click at [cldrjs releases tab](https://github.com/rxaviers/cldrjs/releases).
|
27
|
+
1. Download the latest package.
|
28
|
+
1. Unzip it.
|
29
|
+
1. Rename the extracted directory `cldrjs` and move it alongside `index.html` and `README.md`.
|
30
|
+
|
31
|
+
Then, you'll get this:
|
32
|
+
|
33
|
+
```
|
34
|
+
.
|
35
|
+
├── cldrjs
|
36
|
+
│ └── dist
|
37
|
+
│ ├── cldr.js
|
38
|
+
│ ├── ...
|
39
|
+
│ └── cldr
|
40
|
+
│ ├── event.js
|
41
|
+
│ ├── supplemental.js
|
42
|
+
│ └── ...
|
43
|
+
├── globalize
|
44
|
+
│ └── dist
|
45
|
+
│ ├── globalize.js
|
46
|
+
│ ├── ...
|
47
|
+
│ └── globalize
|
48
|
+
│ ├── currency.js
|
49
|
+
│ ├── date.js
|
50
|
+
│ └── ...
|
51
|
+
├── index.html
|
52
|
+
└── README.md
|
53
|
+
```
|
54
|
+
|
55
|
+
For more information read [cldrjs' usage and
|
56
|
+
installation](https://github.com/rxaviers/cldrjs#usage-and-installation) docs.
|
57
|
+
|
58
|
+
**2. CLDR content**
|
59
|
+
|
60
|
+
Another typical Globalize requirement is to fetch CLDR content yourself. But, on
|
61
|
+
this demo we made the things a little easier for you: we've embedded static JSON
|
62
|
+
into the demo. So, you don't need to actually fetch it anywhere. For more
|
63
|
+
information about fetching Unicode CLDR JSON data, see [How do I get CLDR
|
64
|
+
data?](../../doc/cldr.md).
|
65
|
+
|
66
|
+
No action needed here.
|
67
|
+
|
68
|
+
**3. Globalize `dist` files**
|
69
|
+
|
70
|
+
*This step only applies if you are building the source files. If you have downloaded a ZIP or a TAR.GZ or are using a package manager (such as bower or npm) to install then you can ignore this step.*
|
71
|
+
|
72
|
+
[Install the development external dependencies](../../README.md#install-development-external-dependencies) and [build the distribution files](../../README.md#build).
|
73
|
+
|
74
|
+
## Running the demo
|
75
|
+
|
76
|
+
Once you've completed the requirements above:
|
77
|
+
|
78
|
+
1. Point your browser at `./index.html`.
|
79
|
+
1. Open your JavaScript console to see the demo output.
|
80
|
+
1. Understand the demo by reading the source code. We have comments there for
|
81
|
+
you.
|