Translator
class Translator is a main class used to format numbers, dates and strings.
Constructor arguments#
| parameter | type |
|---|---|
| language | String |
| locales(optional) | Locale[] (by default []) |
Methods#
formatDate#
Format value of a date. This is based on Intl.DateTimeFormat. You can find supported options on MDN.
| parameter | type |
|---|---|
| value | Date |
| options(optional) | Intl.DateTimeFormatOptions |
Example#
formatNumber#
Format value of a number. This is based on Intl.NumberFormat. You can find supported options on MDN.
| parameter | type |
|---|---|
| value | Number |
| options(optional) | Intl.NumberFormatOptions |
Example#
translate#
Get a message paired with the ID and format that message.
It can replace {key} inside the message with values and support plural formatting.
| parameter | type |
|---|---|
| id | String |
| options(optional) | FormatMessageOptions (by default {}) |
Example#
getMessageById#
Get a raw message paired with the ID.
| parameter | type |
|---|---|
| id | String |
| defaultMessage(optional) | String |