globalize-rpk 1.7.0

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.
Files changed (65) hide show
  1. package/CONTRIBUTING.md +5 -0
  2. package/LICENSE +20 -0
  3. package/README.md +818 -0
  4. package/doc/api/core/constructor.md +28 -0
  5. package/doc/api/core/load.md +96 -0
  6. package/doc/api/core/locale.md +43 -0
  7. package/doc/api/currency/currency-formatter.md +196 -0
  8. package/doc/api/currency/currency-to-parts-formatter.md +117 -0
  9. package/doc/api/date/date-formatter.md +203 -0
  10. package/doc/api/date/date-parser.md +60 -0
  11. package/doc/api/date/date-to-parts-formatter.md +176 -0
  12. package/doc/api/date/load-iana-time-zone.md +29 -0
  13. package/doc/api/message/load-messages.md +105 -0
  14. package/doc/api/message/message-formatter.md +208 -0
  15. package/doc/api/number/number-formatter.md +202 -0
  16. package/doc/api/number/number-parser.md +130 -0
  17. package/doc/api/number/number-to-parts-formatter.md +140 -0
  18. package/doc/api/plural/plural-generator.md +84 -0
  19. package/doc/api/relative-time/relative-time-formatter.md +60 -0
  20. package/doc/api/unit/unit-formatter.md +72 -0
  21. package/doc/blog-post/2017-07-xx-1.3.0-announcement.md +177 -0
  22. package/doc/cldr.md +114 -0
  23. package/doc/error/e-default-locale-not-defined.md +9 -0
  24. package/doc/error/e-invalid-cldr.md +14 -0
  25. package/doc/error/e-invalid-par-type.md +12 -0
  26. package/doc/error/e-invalid-par-value.md +11 -0
  27. package/doc/error/e-missing-cldr.md +11 -0
  28. package/doc/error/e-missing-parameter.md +10 -0
  29. package/doc/error/e-missing-plural-module.md +9 -0
  30. package/doc/error/e-par-missing-key.md +11 -0
  31. package/doc/error/e-par-out-of-range.md +13 -0
  32. package/doc/error/e-unsupported.md +10 -0
  33. package/doc/migrating-from-0.x.md +64 -0
  34. package/examples/amd-bower/.bowerrc +7 -0
  35. package/examples/amd-bower/README.md +65 -0
  36. package/examples/amd-bower/bower.json +13 -0
  37. package/examples/amd-bower/index.html +46 -0
  38. package/examples/amd-bower/main.js +141 -0
  39. package/examples/amd-bower/messages/en.json +12 -0
  40. package/examples/amd-bower/package.json +14 -0
  41. package/examples/app-npm-webpack/README.md +74 -0
  42. package/examples/app-npm-webpack/app/index.js +89 -0
  43. package/examples/app-npm-webpack/index-template.html +71 -0
  44. package/examples/app-npm-webpack/messages/ar.json +25 -0
  45. package/examples/app-npm-webpack/messages/de.json +21 -0
  46. package/examples/app-npm-webpack/messages/en.json +21 -0
  47. package/examples/app-npm-webpack/messages/es.json +21 -0
  48. package/examples/app-npm-webpack/messages/pt.json +21 -0
  49. package/examples/app-npm-webpack/messages/ru.json +23 -0
  50. package/examples/app-npm-webpack/messages/zh.json +20 -0
  51. package/examples/app-npm-webpack/package.json +17 -0
  52. package/examples/app-npm-webpack/webpack-config.js +63 -0
  53. package/examples/globalize-compiler/README.md +45 -0
  54. package/examples/globalize-compiler/app.js +58 -0
  55. package/examples/globalize-compiler/development.html +121 -0
  56. package/examples/globalize-compiler/messages.json +12 -0
  57. package/examples/globalize-compiler/package.json +15 -0
  58. package/examples/globalize-compiler/production.html +75 -0
  59. package/examples/node-npm/README.md +57 -0
  60. package/examples/node-npm/main.js +65 -0
  61. package/examples/node-npm/messages/en.json +12 -0
  62. package/examples/node-npm/package.json +10 -0
  63. package/examples/plain-javascript/README.md +81 -0
  64. package/examples/plain-javascript/index.html +445 -0
  65. package/package.json +109 -0
@@ -0,0 +1,60 @@
1
+ ## .dateParser( [options] ) ➜ function( value )
2
+
3
+ Return a function that parses a string representing a date into a JavaScript Date object according to the given `options`. The default parsing assumes numeric year, month, and day (i.e., `{ skeleton: "yMd" }`).
4
+
5
+ The returned function is invoked with one argument: the String `value` to be parsed.
6
+
7
+ ### Parameters
8
+
9
+ #### options
10
+
11
+ See [.dateFormatter() options](./date-formatter.md#parameters).
12
+
13
+ #### value
14
+
15
+ String with date to be parsed, eg. `"11/1/10, 5:55 PM"`.
16
+
17
+ ### Example
18
+
19
+ Prior to using any date methods, you must load `cldr/main/{locale}/ca-gregorian.json`, `cldr/main/{locale}/timeZoneNames.json`, `cldr/supplemental/timeData.json`, `cldr/supplemental/weekData.json`, and the CLDR content required by the number module. Read [CLDR content][] if you need more information.
20
+
21
+ [CLDR content]: ../../../README.md#2-cldr-content
22
+
23
+ You can use the static method `Globalize.dateParser()`, which uses the default locale.
24
+
25
+ ```javascript
26
+ var parser;
27
+
28
+ Globalize.locale( "en" );
29
+ parser = Globalize.dateParser();
30
+
31
+ parser( "1/2/2013" );
32
+ // > Wed Jan 02 2013 00:00:00
33
+
34
+ Globalize.locale( "es" );
35
+ parser = Globalize.dateParser();
36
+
37
+ parser( "1/2/2013" );
38
+ // > Fri Feb 01 2013 00:00:00
39
+ ```
40
+
41
+ You can use the instance method `.dateParser()`, which uses the instance locale.
42
+
43
+ ```javascript
44
+ var esParser = Globalize( "es" ).dateParser({ date: short });
45
+
46
+ esParser( "1/2/13" );
47
+ // > Fri Feb 01 2013 00:00:00
48
+ ```
49
+
50
+ For improved performance on iterations, first create the parser. Then, reuse it
51
+ on each loop.
52
+
53
+ ```javascript
54
+ var formattedDates = [ new Date( a ), new Date( b ), ... ];
55
+ var parser = Globalize( "en" ).dateParser({ time: "short" });
56
+
57
+ dates = formattedDates.map(function( formattedDate ) {
58
+ return parser( formattedDate );
59
+ });
60
+ ```
@@ -0,0 +1,176 @@
1
+ ## .dateToPartsFormatter( [options] ) ➜ function( value )
2
+
3
+ Return a function that formats a date into parts tokens according to the given `options`. The default formatting is numeric year, month, and day (i.e., `{ skeleton: "yMd" }`.
4
+
5
+ The returned function is invoked with one argument: the Date instance `value` to be formatted.
6
+
7
+ ### Parameters
8
+
9
+ #### options
10
+
11
+ Please, see [.dateFormatter() options](./date-formatter.md#parameters).
12
+
13
+ #### value
14
+
15
+ Date instance to be formatted, eg. `new Date()`;
16
+
17
+ ### Returns
18
+
19
+ An Array of objects containing the formatted date in parts. The returned structure looks like this:
20
+
21
+ ```js
22
+ [
23
+ { type: "day", value: "17" },
24
+ { type: "weekday", value: "Monday" }
25
+ ]
26
+ ```
27
+
28
+ Possible types are the following:
29
+
30
+ - `day`
31
+
32
+ The string used for the day, e.g., `"17"`, `"١٦"`.
33
+
34
+ - `dayperiod`
35
+
36
+ The string used for the day period, e.g., `"AM"`, `"PM"`.
37
+
38
+ - `era`
39
+
40
+ The string used for the era, e.g., `"AD"`, `"d. C."`.
41
+
42
+ - `hour`
43
+
44
+ The string used for the hour, e.g., `"3"`, `"03"`.
45
+
46
+ - `literal`
47
+
48
+ The string used for separating date and time values, e.g., `"/"`, `", "`,
49
+ `"o'clock"`, `" de "`.
50
+
51
+ - `minute`
52
+
53
+ The string used for the minute, e.g., `"00"`.
54
+
55
+ - `month`
56
+
57
+ The string used for the month, e.g., `"12"`.
58
+
59
+ - `second`
60
+
61
+ The string used for the second, e.g., `"07"` or `"42"`.
62
+
63
+ - `zone`
64
+
65
+ The string used for the name of the time zone, e.g., `"EST".`
66
+
67
+ - `weekday`
68
+
69
+ The string used for the weekday, e.g., `"M"`, `"Monday"`, `"Montag".`
70
+
71
+ - `year`
72
+
73
+ The string used for the year, e.g., `"2012"`, `"96".`
74
+
75
+
76
+ ### Example
77
+
78
+ Prior to using any date methods, you must load `cldr/main/{locale}/ca-gregorian.json`, `cldr/main/{locale}/timeZoneNames.json`, `cldr/supplemental/timeData.json`, `cldr/supplemental/weekData.json`, and the CLDR content required by the number module. Read [CLDR content][] if you need more information.
79
+
80
+ [CLDR content]: ../../../README.md#2-cldr-content
81
+
82
+ You can use the static method `Globalize.dateToPartsFormatter()`, which uses the default locale.
83
+
84
+ ```javascript
85
+ var formatter;
86
+
87
+ Globalize.locale( "en" );
88
+ formatter = Globalize.dateToPartsFormatter();
89
+
90
+ formatter( new Date( 2010, 10, 30 ) );
91
+ // > [
92
+ // { "type": "month", "value": "11" },
93
+ // { "type": "literal", "value": "/" },
94
+ // { "type": "day", "value": "30" },
95
+ // { "type": "literal", "value": "/" },
96
+ // { "type": "year", "value": "2010" }
97
+ // ]
98
+ ```
99
+
100
+ You can use the instance method `.dateToPartsFormatter()`, which uses the instance locale.
101
+
102
+ ```javascript
103
+ var enFormatter = Globalize( "en" ).dateToPartsFormatter(),
104
+ deFormatter = Globalize( "de" ).dateToPartsFormatter();
105
+
106
+ enFormatter( new Date( 2010, 10, 30 ) );
107
+ // > [
108
+ // { "type": "month", "value": "11" },
109
+ // { "type": "literal", "value": "/" },
110
+ // { "type": "day", "value": "30" },
111
+ // { "type": "literal", "value": "/" },
112
+ // { "type": "year", "value": "2010" }
113
+ // ]
114
+
115
+ deFormatter( new Date( 2010, 10, 30 ) );
116
+ // > [
117
+ // { type: 'day', value: '30' },
118
+ // { type: 'literal', value: '.' },
119
+ // { type: 'month', value: '11' },
120
+ // { type: 'literal', value: '.' },
121
+ // { type: 'year', value: '2010' }
122
+ // ]
123
+ ```
124
+
125
+ The information is available separately and it can be formatted and concatenated again in a customized way. For example by using [`Array.prototype.map()`][], [arrow functions][], a [switch statement][], [template literals][], and [`Array.prototype.reduce()`][].
126
+
127
+ [`Array.prototype.map()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
128
+ [arrow functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
129
+ [switch statement]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
130
+ [template literals]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
131
+ [`Array.prototype.reduce()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
132
+
133
+ ```javascript
134
+ var formatter;
135
+
136
+ Globalize.locale( "en" );
137
+ formatter = Globalize.dateToPartsFormatter({datetime: "short"});
138
+
139
+ formatter( new Date( 2010, 10, 30, 17, 55 ) ).map(({type, value}) => {
140
+ switch ( type ) {
141
+ case "year": return `<strong>${value}</strong>`;
142
+ default: return value;
143
+ }
144
+ }).join( "" );
145
+ // > "11/30/<strong>10</strong>, 5:55 PM"
146
+ ```
147
+
148
+ Please, see [.dateFormatter() example](./date-formatter.md#example) for additional examples such as using `date`, `time`, `datetime`, and `skeleton` options.
149
+
150
+ For improved performance on iterations, first create the formatter. Then, reuse it on each loop.
151
+
152
+ ```javascript
153
+ // In an application, this array could have a few hundred entries
154
+ var dates = [ new Date( 2010, 10, 30, 17, 55 ), new Date( 2015, 3, 18, 4, 25 ) ];
155
+ var formatter = Globalize( "en" ).dateToPartsFormatter({ time: "short" });
156
+
157
+ var formattedDates = dates.map(function( date ) {
158
+ return formatter( date );
159
+ });
160
+ // > [
161
+ // [
162
+ // { "type": "hour", "value": "5" },
163
+ // { "type": "literal", "value": ":" },
164
+ // { "type": "minute", "value": "55" },
165
+ // { "type": "literal", "value": " " },
166
+ // { "type": "dayperiod", "value": "PM" }
167
+ // ],
168
+ // [
169
+ // { "type": "hour", "value": "4" },
170
+ // { "type": "literal", "value": ":" },
171
+ // { "type": "minute", "value": "25" },
172
+ // { "type": "literal", "value": " " },
173
+ // { "type": "dayperiod", "value": "AM" }
174
+ // ]
175
+ // ]
176
+ ```
@@ -0,0 +1,29 @@
1
+ ## Globalize.loadTimeZone( ianaTzData )
2
+
3
+ This method allows you to load IANA time zone data to enable `options.timeZone` feature on date formatters and parsers.
4
+
5
+ ### Parameters
6
+
7
+ #### ianaTzData
8
+
9
+ A JSON object with zdumped IANA timezone data. Get the data via [`iana-tz-data`](https://github.com/rxaviers/iana-tz-data).
10
+
11
+ ### Example
12
+
13
+ ```javascript
14
+ Globalize.loadTimeZone({
15
+ "zoneData": {
16
+ ...
17
+ "America": {
18
+ ...
19
+ "New_York": {
20
+ abbrs: [],
21
+ untils: [],
22
+ offsets: [],
23
+ isdsts: []
24
+ }
25
+ ...
26
+ }
27
+ }
28
+ });
29
+ ```
@@ -0,0 +1,105 @@
1
+ ## .loadMessages( json )
2
+
3
+ Load messages data.
4
+
5
+ The first level of keys must be locales. For example:
6
+
7
+ ```
8
+ {
9
+ en: {
10
+ hello: "Hello"
11
+ },
12
+ pt: {
13
+ hello: "Olá"
14
+ }
15
+ }
16
+ ```
17
+
18
+ ICU MessageFormat pattern is supported: variable replacement, gender and plural inflections. For more information see [`.messageFormatter( path ) ➡ function([ variables ])`](./message-formatter.md).
19
+
20
+ The provided messages are stored along side other cldr data, under the "globalize-messages" key. This allows Globalize to reuse the traversal methods provided by cldrjs. You can inspect this data using `cldrjs.get("globalize-messages")`.
21
+
22
+ ### Parameters
23
+
24
+ #### json
25
+
26
+ JSON object of messages data. Keys can use any character, except `/`, `{` and `}`. Values (i.e., the message content itself) can contain any character.
27
+
28
+ ### Example
29
+
30
+ ```javascript
31
+ Globalize.loadMessages({
32
+ pt: {
33
+ greetings: {
34
+ hello: "Olá",
35
+ bye: "Tchau"
36
+ }
37
+ }
38
+ });
39
+
40
+ Globalize( "pt" ).formatMessage( "greetings/hello" );
41
+ // > Olá
42
+ ```
43
+
44
+ #### Multiline strings
45
+
46
+ Use Arrays as a convenience for multiline strings. The lines will be joined by a space.
47
+
48
+ ```javascript
49
+ Globalize.loadMessages({
50
+ en: {
51
+ longText: [
52
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi non",
53
+ "quis exercitationem culpa nesciunt nihil aut nostrum explicabo",
54
+ "reprehenderit optio amet ab temporibus asperiores quasi cupiditate.",
55
+ "Voluptatum ducimus voluptates voluptas?"
56
+ ]
57
+ }
58
+ });
59
+
60
+ Globalize( "en" ).formatMessage( "longText" );
61
+ // > "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi non quis exercitationem culpa nesciunt nihil aut nostrum explicabo reprehenderit optio amet ab temporibus asperiores quasi cupiditate. Voluptatum ducimus voluptates voluptas?"
62
+ ```
63
+
64
+ #### Messages inheritance
65
+
66
+ It's possible to inherit messages, for example:
67
+
68
+ ```javascript
69
+ Globalize.loadMessages({
70
+ root: {
71
+ amen: "Amen"
72
+ },
73
+ de: {},
74
+ en: {},
75
+ "en-GB": {},
76
+ fr: {},
77
+ pt: {
78
+ amen: "Amém"
79
+ },
80
+ "pt-PT": {}
81
+ });
82
+
83
+ Globalize( "de" ).formatMessage( "amen" );
84
+ // > "Amen"
85
+
86
+ Globalize( "en" ).formatMessage( "amen" );
87
+ // > "Amen"
88
+
89
+ Globalize( "en-GB" ).formatMessage( "amen" );
90
+ // > "Amen"
91
+
92
+ Globalize( "fr" ).formatMessage( "amen" );
93
+ // > "Amen"
94
+
95
+ Globalize( "pt-PT" ).formatMessage( "amen" );
96
+ // > "Amém"
97
+ ```
98
+
99
+ Note that `de`, `en`, `en-GB`, `fr`, and `pt-PT` are empty. `.formatMessage()` inherits `pt-PT` messages from `pt` (`pt-PT` ➡ `pt`), and it inherits the other messages from root, eg. `en-GB` ➡ `en-001` ➡ `en` ➡ `root`. Yes, `root` is the last bundle of the parent lookup.
100
+
101
+ Attention: On browsers, message inheritance only works if the optional dependency `cldr/unresolved` is loaded.
102
+
103
+ ```html
104
+ <script src="cldr/unresolved.js"></script>
105
+ ```
@@ -0,0 +1,208 @@
1
+ ## .messageFormatter( path ) ➡ function([ variables ])
2
+
3
+ Return a function that formats a message (using ICU message format pattern) given its path and a set of variables into a user-readable string. It supports pluralization and gender inflections.
4
+
5
+ Use [`Globalize.loadMessages( json )`](./load-messages.md) to load
6
+ messages data.
7
+
8
+ ### Parameters
9
+
10
+ #### path
11
+
12
+ String or Array containing the path of the message content, eg., `"greetings/bye"`, or `[ "greetings", "bye" ]`.
13
+
14
+ #### variables
15
+
16
+ Optional. Variables can be Objects, where each property can be referenced by name inside a message; or Arrays, where each entry of the Array can be used inside a message, using numeric indices. When passing one or more arguments of other types, they're converted to an Array and used as such.
17
+
18
+ ### Example
19
+
20
+ You can use the static method `Globalize.messageFormatter()`, which uses the default locale.
21
+
22
+ ```javascript
23
+ var formatter;
24
+
25
+ Globalize.loadMessages({
26
+ pt: {
27
+ greetings: {
28
+ bye: "Tchau"
29
+ }
30
+ }
31
+ });
32
+
33
+ Globalize.locale( "pt" );
34
+ formatter = Globalize.messageFormatter( "greetings/bye" );
35
+
36
+ formatter();
37
+ // > "Tchau"
38
+ ```
39
+
40
+ You can use the instance method `.messageFormatter()`, which uses the instance locale.
41
+
42
+ ```javascript
43
+ var pt = new Globalize( "pt" ),
44
+ formatter = pt.messageFormatter( "greetings/bye" );
45
+
46
+ formatter();
47
+ // > "Tchau"
48
+ ```
49
+
50
+ #### Simple Variable Replacement
51
+
52
+ ```javascript
53
+ var formatter;
54
+
55
+ Globalize.loadMessages({
56
+ en: {
57
+ hello: "Hello, {0} {1} {2}",
58
+ hey: "Hey, {first} {middle} {last}"
59
+ }
60
+ });
61
+
62
+ formatter = Globalize( "en" ).messageFormatter( "hello" );
63
+
64
+ // Numbered variables using Array.
65
+ formatter([ "Wolfgang", "Amadeus", "Mozart" ]);
66
+ // > "Hello, Wolfgang Amadeus Mozart"
67
+
68
+ // Numbered variables using function arguments.
69
+ formatter( "Wolfgang", "Amadeus", "Mozart" );
70
+ // > "Hello, Wolfgang Amadeus Mozart"
71
+
72
+ // Named variables using Object key-value pairs.
73
+ formatter = Globalize( "en" ).messageFormatter( "hey" );
74
+ formatter({
75
+ first: "Wolfgang",
76
+ middle: "Amadeus",
77
+ last: "Mozart"
78
+ });
79
+ // > "Hey, Wolfgang Amadeus Mozart"
80
+ ```
81
+
82
+ #### Gender inflections
83
+
84
+ `select` can be used to format any message variations that works like a switch.
85
+
86
+ ```javascript
87
+ var formatter;
88
+
89
+ // Note you can define multiple lines message using an Array of Strings.
90
+ Globalize.loadMessages({
91
+ en: {
92
+ party: [
93
+ "{hostGender, select,",
94
+ " female {{host} invites {guest} to her party}",
95
+ " male {{host} invites {guest} to his party}",
96
+ " other {{host} invites {guest} to their party}",
97
+ "}"
98
+ ]
99
+ }
100
+ });
101
+
102
+ formatter = Globalize( "en" ).messageFormatter( "party" );
103
+
104
+ formatter({
105
+ guest: "Mozart",
106
+ host: "Beethoven",
107
+ hostGender: "male"
108
+ });
109
+ // > "Beethoven invites Mozart to his party"
110
+ ```
111
+
112
+ #### Plural inflections
113
+
114
+ It uses the plural forms `zero`, `one`, `two`, `few`, `many`, or `other` (required). Note English only uses `one` and `other`. So, including `zero` will never get called, even when the number is 0. For more information see [`.pluralGenerator()`](../plural/plural-generator.md).
115
+
116
+ ```javascript
117
+ var numberFormatter, taskFormatter,
118
+ en = new Globalize( "en" );
119
+
120
+ // Note you can define multiple lines message using an Array of Strings.
121
+ Globalize.loadMessages({
122
+ en: {
123
+ task: [
124
+ "You have {count, plural,",
125
+ " one {one task}",
126
+ " other {{formattedCount} tasks}",
127
+ "} remaining"
128
+ ]
129
+ }
130
+ });
131
+
132
+ numberFormatter = en.numberFormatter();
133
+ taskFormatter = en.messageFormatter( "task" );
134
+
135
+ taskFormatter({
136
+ count: 1000,
137
+ formattedCount: numberFormatter( 1000 )
138
+ });
139
+ // > "You have 1,000 tasks remaining"
140
+ ```
141
+
142
+ Literal numeric keys can be used in `plural` to match single, specific numbers.
143
+
144
+ ```javascript
145
+ var taskFormatter,
146
+ en = new Globalize( "en" );
147
+
148
+ // Note you can define multiple lines message using an Array of Strings.
149
+ Globalize.loadMessages({
150
+ en: {
151
+ task: [
152
+ "You have {count, plural,",
153
+ " =0 {no tasks}",
154
+ " one {one task}",
155
+ " other {{formattedCount} tasks}",
156
+ "} remaining"
157
+ ]
158
+ }
159
+ });
160
+
161
+ taskFormatter = Globalize( "en" ).messageFormatter( "task" );
162
+
163
+ taskFormatter({
164
+ count: 0,
165
+ formattedCount: en.numberFormatter( 0 )
166
+ });
167
+ // > "You have no tasks remaining"
168
+ ```
169
+
170
+ You may find useful having the plural forms calculated with an offset applied.
171
+ Use `#` to output the resulting number. Note literal numeric keys do NOT use the
172
+ offset value.
173
+
174
+ ```javascript
175
+ var likeFormatter,
176
+ en = new Globalize( "en" );
177
+
178
+ Globalize.loadMessages({
179
+ en: {
180
+ likeIncludingMe: [
181
+ "{0, plural, offset:1",
182
+ " =0 {Be the first to like this}",
183
+ " =1 {You liked this}",
184
+ " one {You and someone else liked this}",
185
+ " other {You and # others liked this}",
186
+ "}"
187
+ ]
188
+ }
189
+ });
190
+
191
+ likeFormatter = Globalize( "en" ).messageFormatter( "likeIncludingMe" );
192
+
193
+ likeFormatter( 0 );
194
+ // > "Be the first to like this"
195
+
196
+ likeFormatter( 1 );
197
+ // > "You liked this"
198
+
199
+ likeFormatter( 2 );
200
+ // > "You and someone else liked this"
201
+
202
+ likeFormatter( 3 );
203
+ // > "You and 2 others liked this"
204
+ ```
205
+
206
+ Read on [SlexAxton/messageFormatter.js][] for more information on regard of ICU MessageFormat.
207
+
208
+ [SlexAxton/messageFormatter.js]: https://github.com/SlexAxton/messageformat.js/#no-frills