@@ -243,15 +243,15 @@ polyglot.t("car", 2);
243243=> " 2 cars"
244244```
245245
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.
246+ If you pass a ` numberFormat ` _ function _ to the constructor, Polyglot will use
247+ it to translate interpolated ` Number ` s to ` String ` s . That's useful because
248+ different locales have different rules for formatting numbers: ` 2,000.56 ` in
249+ English versus ` 1 234,56 ` in French, for instance.
250250
251251``` js
252252polyglot = new Polyglot ({
253253 phrases: { num_cars: ' %{smart_count} car |||| %{smart_count} cars' },
254- numberFormat: new Intl.NumberFormat (' en' ) // Chrome, Firefox, IE11+, Node 0.12+ with ICU
254+ numberFormat: new Intl.NumberFormat (' en' ). format // Chrome, Firefox, IE11+, Node 0.12+ with ICU
255255})
256256polyglot .t (" num_cars" , 2000 ); // internally, calls options.numberFormat.format(2000)
257257=> " 2,000 cars"
@@ -261,7 +261,9 @@ polyglot.t("num_cars", 2000); // internally, calls options.numberFormat.format(2
261261in Node: Node 0.12+ comes with Intl as long as it's compiled with ICU (which is
262262the default). By default, the only locale Node supports is en-US. You can add
263263[ full-icu] ( https://www.npmjs.com/package/full-icu ) to your project to support
264- other locales.
264+ other locales. Finally, Polyglot accepts a _ function_ , not an Intl.NumberFormat
265+ instance: if you have a NumberFormat instance, pass its ` .format ` property to
266+ Polyglot.
265267
266268If you like, you can provide a default value in case the phrase is missing.
267269Use the special option key "_ " to specify a default.
0 commit comments