Skip to content

Commit

Permalink
Use locales as first argument
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed May 6, 2024
1 parent 968327f commit de0d1b4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 297 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ In code, with the API proposed below, this would be used like this:

```js
const source = ... // string source of the message as above
const mf = new Intl.MessageFormat(source, 'en');
const mf = new Intl.MessageFormat('en', source);
const notifications = mf.format({ count: 1 });
// 'You have 1 new notification'
```
Expand All @@ -79,11 +79,11 @@ those are of course also supported by the proposed API:

```js
// A plain message
const mf1 = new Intl.MessageFormat('Hello!', 'en');
const mf1 = new Intl.MessageFormat('en', 'Hello!');
mf1.format(); // 'Hello!'

// A parametric message, formatted to parts
const mf2 = new Intl.MessageFormat('Hello {$place}!', 'en');
const mf2 = new Intl.MessageFormat('en', 'Hello {$place}!');
const greet = mf2.formatToParts({ place: 'world' });
/* [
{ type: 'text', value: 'Hello ' },
Expand Down Expand Up @@ -144,8 +144,8 @@ Calling the constructor may throw an error if the `source` includes an MF2
```ts
interface MessageFormat {
new (
locales: string | string[] | undefined,
source: MessageData | string,
locales?: string | string[],
options?: MessageFormatOptions
): MessageFormat;

Expand Down
Loading

0 comments on commit de0d1b4

Please sign in to comment.