MessageFormatClassic
The MessageFormatClassic
API adopts the classic
ICU MessageFormat
patterns for formatting messages.
The MessageFormatClassic
API supports both named-argument style and numbered-argument style in patterns.
Use the named-argument style to improve readability for developers and translators by providing descriptively
named arguments. In addition, that can better infer what kind of values go into the arguments in a pattern.
Examples
import { MessageFormatClassic } from '@amazon-devices/keplerscript-kepleri18n-lib';
...
// Retrieve the pattern from the string resources. It's hardcoded here to simplify the example.
const pattern: string = "Car number {carNumber} wins! Congratulations, {driverName}!";
const carNumber: number = 3;
const driverName: string = "Alice";
const argMap = new Map<string, number | string | Date>();
argMap.set("carNumber", carNumber);
argMap.set("driverName", driverName);
const message: string | null = MessageFormatClassic.format(pattern, argMap);
if (message === null) {
// Error
return;
}
// message is "Car number 3 wins! Congratulations, Alice!".
import { MessageFormatClassic } from '@amazon-devices/keplerscript-kepleri18n-lib';
...
// Retrieve the pattern from the string resources. It's hardcoded here to simplify the example.
const pattern: string = "Car number {0} wins! Congratulations, {1}!";
const carNumber: number = 11;
const driverName: string = "Bob";
const message: string | null = MessageFormatClassic.formatPositional(pattern, carNumber, driverName);
if (message === null) {
// Error
return;
}
// message is "Car number 11 wins! Congratulations, Bob!".
Constructors
new MessageFormatClassic()
new MessageFormatClassic():
MessageFormatClassic
Returns
Methods
format()
static
format(pattern
,args
):null
|string
Formats the specified pattern with named arguments in the default locale.
Parameters
pattern
string
A classic message format pattern.
args
Map
<string
, string
| number
| Date
>
Map of argument names to their values.
Returns
null
| string
Formatted message on success, null on failure.
formatPositional()
static
formatPositional(pattern
, …args
):null
|string
Formats the specified pattern with numbered arguments in the default locale.
Parameters
pattern
string
A classic message format pattern.
args
…(string
| number
| Date
)[]
Array of argument values
Returns
null
| string
Formatted message on success, null on failure.
formatPositionalWithLocale()
static
formatPositionalWithLocale(pattern
,locale
, …args
):null
|string
Formats the specified pattern with numbered arguments in the specified locale.
Parameters
pattern
string
A classic message format pattern.
locale
A BCP-47 locale string. If this parameter is null or an empty string, the default locale is used.
null |
string |
args
…(string
| number
| Date
)[]
Array of argument values
Returns
null
| string
Formatted message on success, null on failure.
formatWithLocale()
static
formatWithLocale(pattern
,locale
,args
):null
|string
Formats the specified pattern with named arguments in the specified locale.
Parameters
pattern
string
A classic message format pattern.
locale
A BCP-47 locale string. If this parameter is null or an empty string, the default locale is used.
null |
string |
args
Map
<string
, string
| number
| Date
>
Map of argument names to their values.
Returns
null
| string
Formatted message on success, null on failure.
getMajorVersion()
static
getMajorVersion():number
Gets the major version number.
Returns
number
Major version number.
getMinorVersion()
static
getMinorVersion():number
Gets the minor version number.
Returns
number
Minor version number.
getPatchVersion()
static
getPatchVersion():number
Gets the patch version number.
Returns
number
Patch version number.
Last updated: Sep 29, 2025