Skip to content

Commit 3b449b7

Browse files
authored
docs: Add reference of I18n.date and I18n.number (#1103)
1 parent acc7788 commit 3b449b7

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

docs/ref/core.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,65 @@ Reference
161161
// Message with custom messageId
162162
i18n._("msg.id", { name: "Tom" }, { defaults: "My name is {name}" })
163163
164+
.. js:method:: date(value: string | Date[, format: Intl.DateTimeFormatOptions])
165+
166+
:returns: Formatted date string
167+
168+
Format a date using the conventional format for the active language.
169+
170+
``date`` is a Date object to be formatted. When ``date`` is a string, the Date object is created by ``new Date(date)``.
171+
172+
``format`` is an object passed to the ``options`` argument of the `Intl.DateTimeFormat constructor <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat>`_ (optional).
173+
174+
.. code-block:: js
175+
176+
import { i18n } from "@lingui/core"
177+
178+
const d = new Date("2021-07-23T16:23:00")
179+
180+
i18n.activate("en")
181+
i18n.date(d)
182+
// Returns "7/23/2021"
183+
184+
i18n.date(d, { timeStyle: "medium"})
185+
// Returns "4:23:00 PM"
186+
187+
i18n.date(d, { dateStyle: "medium", timeStyle: "medium"})
188+
// Returns "Jul 23, 2021, 4:23:00 PM"
189+
190+
i18n.activate("cs")
191+
i18n.date(d)
192+
// Returns "23. 7. 2021"
193+
194+
195+
.. js:method:: number(value: number[, format: Intl.NumberFormatOptions])
196+
197+
:returns: Formatted number string
198+
199+
Format a number using the conventional format for the active language.
200+
201+
``number`` is a number to be formatted.
202+
203+
``format`` is an object passed to the ``options`` argument of the `Intl.NumberFormat constructor <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat>`_ (optional).
204+
205+
.. code-block:: js
206+
207+
import { i18n } from "@lingui/core"
208+
209+
i18n.activate("en")
210+
i18n.number(12345.678)
211+
// Returns "12,345.678"
212+
213+
i18n.number(12345.678, { style: "currency", currency: "USD"})
214+
// Returns "$12,345.68"
215+
216+
i18n.activate("cs")
217+
i18n.number(12345.678)
218+
// Returns "12 345,678"
219+
220+
i18n.number(12345.678, { style: "currency", currency: "CZK"})
221+
// Returns "12 345,68 Kč"
222+
164223
.. js:function:: setupI18n([options])
165224

166225
:returns: instance of I18n

0 commit comments

Comments
 (0)