@@ -243,24 +243,25 @@ polyglot.t("car", 2);
243243=> " 2 cars"
244244```
245245
246- Interpolated ` Number ` s will be number-formatted according to the ` locale ` :
246+ If you pass a ` numberFormat ` to the constructor, interpolated ` Number ` s will
247+ be formatted by its ` format() ` method. That's useful because different locales
248+ have different rules for formatting numbers: ` 2,000.56 ` in English versus
249+ ` 1 234,56 ` in French, for instance.
247250
248251``` js
249- polyglot .t (" num_cars" , 2000 );
252+ polyglot = new Polyglot ({
253+ phrases: { num_cars: ' %{smart_count} car |||| %{smart_count} cars' },
254+ numberFormat: new Intl.NumberFormat (' en' ) // Chrome, Firefox, IE11+, Node 0.12+ with ICU
255+ })
256+ polyglot .t (" num_cars" , 2000 ); // internally, calls options.numberFormat.format(2000)
250257=> " 2,000 cars"
251258```
252259
253- On a default Node install, this may only work in English. To format in
254- non-English locales (e.g., to output "2.000" in France or use other numerals),
255- compile Node with "full" ICU data or include the ` full-icu ` package in your
256- project:
257-
258- 1 . ` npm install --save full-icu `
259- 2 . Run ` node --full-data-dir=node_modules/full-icu ` instead of just ` node ` , or
260- set the ` NODE_ICU_DATA=node_modules/full-icu ` environment variable.
261-
262- If you're running Polyglot within a browser, it can number-format in any
263- locale the web browser supports.
260+ (A primer on [ Intl.NumberFormat] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat )
261+ in Node: Node 0.12+ comes with Intl as long as it's compiled with ICU (which is
262+ the default). By default, the only locale Node supports is en-US. You can add
263+ [ full-icu] ( https://www.npmjs.com/package/full-icu ) to your project to support
264+ other locales.
264265
265266If you like, you can provide a default value in case the phrase is missing.
266267Use the special option key "_ " to specify a default.
0 commit comments