Translator
class Translator
is a main class used to format numbers, dates and strings.
#
Constructor argumentsparameter | type |
---|---|
language | String |
locales(optional) | Locale[] (by default []) |
#
Methods#
formatDateFormat 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#
formatNumberFormat 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#
translateGet 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#
getMessageByIdGet a raw message paired with the ID.
parameter | type |
---|---|
id | String |
defaultMessage(optional) | String |