+
new MessageFormat( [locale] [, options])
+ + +Create a new MessageFormat compiler
+import MessageFormat from 'messageformat'
+
+ Parameters:
+ + +Name | + + +Type | + + +Argument | + + + + +Description | +
---|---|---|---|
locale |
+
+
+ + + +string +| + +Array + + + + + | + + +
+
+ <optional> + + + + + + |
+
+
+
+
+ Define the locale or locales supported by this MessageFormat instance. If
+given multiple valid locales, the first will be the default. If String If |
+
options |
+
+
+ + + +MessageFormat~Options + + + + + | + + +
+
+ <optional> + + + + + + |
+
+
+
+
+ Compiler options |
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
Members
+ +-
+
+
-
+
<static> defaultLocale
+ + +
+ -
+
+ ++ + + + + +
Used by the constructor when no
+locale
argument is given.-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Default Value: +
-
+
-
+
- 'en' +
+
+
+
+
+
+ - Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
+
+
+
Methods
+ +-
+
+
+
-
+
<static> escape(str [, octothorpe])
+ + +
+
+ -
+
+
+ ++ + + + + + + + +
Escape special characaters by surrounding the characters
+{
and}
in the +input string with 'quotes'. This will allow those characters to not be +considered as MessageFormat control characters.Parameters:
+ + ++ +
+ + + + ++ + + + + + + +Name + + +Type + + +Argument + + + +Default + + +Description ++ + + + + + + + +str
+ + +string + + + + + + + ++ + + + + + + + + ++ + + + + +The input string
+ + + + + + + + +octothorpe
+ + +boolean + + + + + + + ++ + <optional> + + + +
+ + + + + ++ + false + + + + + +Also escape
#
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
Returns:
+ + +++ + + +The escaped string
+-
+
- + Type + +
- + +string + + + + +
+
+
+
+
+ -
+
<static> supportedLocalesOf(locales)
+ + +
+
+ -
+
+
+ ++ + + + + + + + +
Returns a subset of
+locales
consisting of those for which MessageFormat +has built-in plural category support.Parameters:
+ + ++ +
+ + + + ++ + + + + + + +Name + + +Type + + + + + +Description ++ + + + + + + + +locales
+ + +string +| + +Array.<string> + + + + + + + + + + ++ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
Returns:
+ + + + +-
+
- + Type + +
- + +Array.<string> + + + + +
+
+
+
+
+ -
+
compile(message)
+ + +
+
+ -
+
+
+ ++ + + + + + + + +
Compile a message into a function
+Given a string
+message
with ICU MessageFormat declarations, the result is +a function taking a single Object parameter representing each of the +input's defined variables, using the first valid locale.Parameters:
+ + ++ +
+ + + + ++ + + + + + + +Name + + +Type + + + + + +Description ++ + + + + + + + +message
+ + +string + + + + + + + + + + + +The input message to be compiled, in ICU MessageFormat
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
Returns:
+ + +++ + + +-
+
- The compiled function +
-
+
- + Type + +
- + +function + + + + +
Example
+ +const mf = new MessageFormat('en') +const msg = mf.compile('A {TYPE} example.') + +msg({ TYPE: 'simple' }) // 'A simple example.'
+ + + +
+
+
+
+
+ -
+
resolvedOptions()
+ + +
+
+ -
+
+
+ ++ + + + + + + + + + +
Returns a new object with properties reflecting the default locale, +plurals, and other options computed during initialization.
+-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
Returns:
+ + + + +-
+
- + Type + +
- + +MessageFormat~ResolvedOptions + + + + +
+
+
+
+
+
+
Type Definitions
+ +-
+
+
-
+
Options
+ + +
+ -
+
+ ++ + + +
The shape of the options object +that may be used as the second argument of the constructor.
+Type:
+-
+
- + +Object + + + + +
-
+
+
+
- Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
Properties:
+ +-
+
+
+ +
++ + + + + + + +Name + + +Type + + +Argument + + + +Default + + +Description ++ + + + + + + + +biDiSupport
+ + +boolean + + + + + + + ++ + <optional> + + + +
+ + + ++ + false + + + + + +Add Unicode control characters to +all input parts to preserve the integrity of the output when mixing LTR +and RTL text
+ + + + + + + + +currency
+ + +string + + + + + + + ++ + <optional> + + + +
+ + + ++ + 'USD' + + + + + +The currency to use when formatting +
{V, number, currency}
+ + + + + + + + +customFormatters
+ + +Object + + + + + + + ++ + <optional> + + + +
+ + + ++ + + + + +Map of custom formatting functions +to include. See the Format Guide for more details.
+ + + + + + + + +requireAllArguments
+ + +boolean + + + + + + + ++ + <optional> + + + +
+ + + ++ + false + + + + + +Require all message +arguments to be set with a defined value
+ + + + + + + + +returnType
+ + +'string' +| + +'values' + + + + + + + ++ + <optional> + + + +
+ + + ++ + 'string' + + + + + +Return type of +compiled functions; either a concatenated string or an array (possibly +hierarchical) of values
+ + + + + + + + +strictNumberSign
+ + +boolean + + + + + + + ++ + <optional> + + + +
+ + + ++ + false + + + + + +Allow
#
only directly +within a plural or selectordinal case, rather than in any inner select +case as well.
+
+
+
+ -
+
ResolvedOptions
+ + +
+ -
+
+
+
+
Type:
+-
+
- + +Object + + + + +
-
+
+
+
- Source: +
-
+
-
+
- + messageformat.js + +
+
+
+
+
+
+
+
+
Properties:
+ +-
+
+
+ +
++ + + + + + + +Name + + +Type + + + + + +Description ++ + + + + + + + +biDiSupport
+ + +boolean + + + + + + + + + + + +Whether Unicode control characters be +added to all input parts to preserve the integrity of the output when +mixing LTR and RTL text
+ + + + + + + + +customFormatters
+ + +object + + + + + + + + + + + +Map of custom formatting functions
+ + + + + + + + +locale
+ + +string + + + + + + + + + + + +The default locale
+ + + + + + + + +plurals
+ + +Array.<object> + + + + + + + + + + + +All of the supported plurals
+ + + + + + + + +strictNumberSign
+ + +boolean + + + + + + + + + + + +Is
#
only allowed directly within +a plural or selectordinal case
+
+
+
+