|
1 | 1 | define([ |
2 | 2 | "globalize", |
3 | 3 | "json!cldr-data/supplemental/likelySubtags.json", |
| 4 | + "json!cldr-data/supplemental/numberingSystems.json", |
| 5 | + "json!cldr-data/supplemental/currencyData.json", |
4 | 6 | "json!cldr-data/supplemental/plurals.json", |
5 | 7 | "json!cldr-data/supplemental/ordinals.json", |
| 8 | + "json!cldr-data/supplemental/timeData.json", |
| 9 | + "json!cldr-data/supplemental/weekData.json", |
| 10 | + "json!cldr-data/main/en/numbers.json", |
| 11 | + "json!cldr-data/main/en/units.json", |
| 12 | + "json!cldr-data/main/en/currencies.json", |
| 13 | + "json!cldr-data/main/en/ca-gregorian.json", |
| 14 | + "json!cldr-data/main/en/timeZoneNames.json", |
| 15 | + "json!cldr-data/main/en/dateFields.json", |
| 16 | + "json!iana-tz-data.json", |
6 | 17 | "../../util", |
7 | 18 |
|
8 | 19 | "cldr/unresolved", |
9 | 20 | "globalize/message", |
10 | 21 | "globalize/plural" |
11 | | -], function( Globalize, likelySubtags, plurals, ordinals, util ) { |
| 22 | +], function( Globalize, likelySubtags, numberingSystems, currencyData, plurals, |
| 23 | + ordinals, timeData, weekData, enNumbers, enUnitFields, enCurrencies, enCaGregorian, |
| 24 | + enTimeZoneNames, enDateFields, ianaTimezoneData, util ) { |
| 25 | + |
| 26 | +function extraSetup() { |
| 27 | + Globalize.load( |
| 28 | + numberingSystems, |
| 29 | + currencyData, |
| 30 | + enNumbers, |
| 31 | + enUnitFields, |
| 32 | + enCurrencies, |
| 33 | + timeData, |
| 34 | + weekData, |
| 35 | + enCaGregorian, |
| 36 | + enTimeZoneNames, |
| 37 | + enDateFields |
| 38 | + ); |
| 39 | + Globalize.loadTimeZone( ianaTimezoneData ); |
| 40 | +} |
12 | 41 |
|
13 | 42 | QUnit.assert.messageFormatter = function( locale, path, variables, expected ) { |
14 | 43 | if ( arguments.length === 3 ) { |
@@ -67,6 +96,31 @@ QUnit.module( ".messageFormatter( path )", { |
67 | 96 | "{cat, selectordinal, one{#st} two{#nd} few{#rd} other{#th} }", |
68 | 97 | "category" |
69 | 98 | ], |
| 99 | + date: { |
| 100 | + date: "date: {x, date, long}", |
| 101 | + time: "time: {x, time, long}", |
| 102 | + datetime: "datetime: {x, datetime, long}" |
| 103 | + }, |
| 104 | + relativetime: { |
| 105 | + default: "relativetime: {x, relativetime, minute}", |
| 106 | + short: "relativetime short: {x, relativetime, minute, short}", |
| 107 | + narrow: "relativetime narrow: {x, relativetime, minute, narrow}" |
| 108 | + }, |
| 109 | + number: { |
| 110 | + decimal: "number decimal: {x, number}", |
| 111 | + percent: "number percent: {x, number, percent}" |
| 112 | + }, |
| 113 | + currency: { |
| 114 | + symbol: "currency symbol: {x, currency, USD}", |
| 115 | + accounting: "currency accounting: {x, currency, USD, accounting}", |
| 116 | + code: "currency code: {x, currency, USD, code}", |
| 117 | + name: "currency name: {x, currency, USD, name}" |
| 118 | + }, |
| 119 | + unit: { |
| 120 | + long: "unit long: {x, unit, second, long}", |
| 121 | + short: "unit short: {x, unit, second, short}", |
| 122 | + narrow: "unit narrow: {x, unit, second, narrow}" |
| 123 | + } |
70 | 124 | }, |
71 | 125 | "en-GB": {}, |
72 | 126 | fr: {}, |
@@ -198,6 +252,71 @@ QUnit.test( "should support ICU message format", function( assert ) { |
198 | 252 | }, "4th category" ); |
199 | 253 | }); |
200 | 254 |
|
| 255 | +QUnit.test( "should support formatters in messages", function( assert ) { |
| 256 | + extraSetup(); |
| 257 | + |
| 258 | + var date = new Date( 2010, 8, 15, 17, 35, 7, 369 ); |
| 259 | + |
| 260 | + assert.messageFormatter( "en", "date/date", { |
| 261 | + x: date, |
| 262 | + }, "date: September 15, 2010" ); |
| 263 | + assert.messageFormatter( "en", "date/time", { |
| 264 | + x: date, |
| 265 | + }, "time: 5:35:07 PM GMT+2" ); |
| 266 | + assert.messageFormatter( "en", "date/datetime", { |
| 267 | + x: date, |
| 268 | + }, "datetime: September 15, 2010 at 5:35:07 PM GMT+2" ); |
| 269 | + |
| 270 | + assert.messageFormatter( "en", "relativetime/default", { |
| 271 | + x: 2, |
| 272 | + }, "relativetime: in 2 minutes" ); |
| 273 | + assert.messageFormatter( "en", "relativetime/default", { |
| 274 | + x: -2, |
| 275 | + }, "relativetime: 2 minutes ago" ); |
| 276 | + assert.messageFormatter( "en", "relativetime/short", { |
| 277 | + x: 2, |
| 278 | + }, "relativetime short: in 2 min." ); |
| 279 | + assert.messageFormatter( "en", "relativetime/short", { |
| 280 | + x: -2, |
| 281 | + }, "relativetime short: 2 min. ago" ); |
| 282 | + assert.messageFormatter( "en", "relativetime/narrow", { |
| 283 | + x: 2, |
| 284 | + }, "relativetime narrow: in 2 min." ); |
| 285 | + assert.messageFormatter( "en", "relativetime/narrow", { |
| 286 | + x: -2, |
| 287 | + }, "relativetime narrow: 2 min. ago" ); |
| 288 | + |
| 289 | + assert.messageFormatter( "en", "number/decimal", { |
| 290 | + x: 0.5, |
| 291 | + }, "number decimal: 0.5" ); |
| 292 | + assert.messageFormatter( "en", "number/percent", { |
| 293 | + x: 0.5, |
| 294 | + }, "number percent: 50%" ); |
| 295 | + |
| 296 | + assert.messageFormatter( "en", "currency/symbol", { |
| 297 | + x: 100, |
| 298 | + }, "currency symbol: $100.00" ); |
| 299 | + assert.messageFormatter( "en", "currency/accounting", { |
| 300 | + x: 100, |
| 301 | + }, "currency accounting: $100.00" ); |
| 302 | + assert.messageFormatter( "en", "currency/code", { |
| 303 | + x: 100, |
| 304 | + }, "currency code: 100.00 USD" ); |
| 305 | + assert.messageFormatter( "en", "currency/name", { |
| 306 | + x: 100, |
| 307 | + }, "currency name: 100.00 US dollars" ); |
| 308 | + |
| 309 | + assert.messageFormatter( "en", "unit/long", { |
| 310 | + x: 42, |
| 311 | + }, "unit long: 42 seconds" ); |
| 312 | + assert.messageFormatter( "en", "unit/short", { |
| 313 | + x: 42, |
| 314 | + }, "unit short: 42 sec" ); |
| 315 | + assert.messageFormatter( "en", "unit/narrow", { |
| 316 | + x: 42, |
| 317 | + }, "unit narrow: 42s" ); |
| 318 | +}); |
| 319 | + |
201 | 320 | // Reference #473 |
202 | 321 | QUnit.test( "should NOT merge array data", function( assert ) { |
203 | 322 | // Re-loading a message that uses array syntax. |
|
0 commit comments