A utility to format string messages. It is influenced by Java's MessageFormat
class and support most of its functionality.
Usage
Install the package using npm
as shown below
npm install --save msg-format
You can import the MessageFormat
class and use it as shown below
String
const text = 'I am {0}!!!';const name = 'Groot';console; // I am Groot!!! // or const text = 'I am {0}!!!I am {1}';const name = 'Groot';const state = 'hungry';console; // I am Groot!!!I am hungry // or const text = 'I am {0}!!!I am {1}';const name = 'Groot';const state = 'hungry';console; // I am Groot!!!I am hungry
Date/Time
const date = ;console; // Current time: 16:32console; // Today: 21/07/2018
Localization
; const date = ;console; // Today is: Sundayconsole; // Aujourd'hui est Dimanche. Bonjour John Doe
MessageLocale
Below is the table with all the supported locale in this library. You can get all the mentioned values from MessageLocale
object.
Language | Code |
---|---|
English | en_GB |
French | fr_FR |
German | de_DE |
Simplified Chinese | zh_CN |
Russian | ru_RU |
Arabic | ar_SA |
Japanese | ja_JP |