Skip to content

Commit 51a4ecb

Browse files
committed
i18n types: Add FormatXmlElementFn, for "rich text formatting" feature
The docs are spotty on this feature, but it seems powerful and worth a try. We'll use it to put a web link on a single word in a translated message, in the style chosen by the web app.
1 parent 7c7b8c2 commit 51a4ecb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/types.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ export type MessageLike =
316316
// https://formatjs.io/docs/react-intl/api/#formatmessage
317317
type MessageFormatPrimitiveValue = string | number | boolean | null | void;
318318

319+
// For rich text formatting:
320+
// https://formatjs.io/docs/react-intl/components/#rich-text-formatting
321+
// Name FormatXMLElementFn found in the docs (our name follows Google's
322+
// style guide for camel case):
323+
// https://formatjs.io/docs/react-intl/api/#formatmessage
324+
// Type taken by hand from TypeScript.
325+
type FormatXmlElementFn = (parts: $ReadOnlyArray<string | Node>) => Node;
326+
319327
/**
320328
* A string to show, translated, in the UI as a plain string.
321329
*
@@ -334,7 +342,10 @@ export type LocalizableText =
334342
*/
335343
export type LocalizableReactText =
336344
| string
337-
| {| +text: string, +values?: {| +[string]: MessageFormatPrimitiveValue | Node |} |};
345+
| {|
346+
+text: string,
347+
+values?: {| +[string]: MessageFormatPrimitiveValue | Node | FormatXmlElementFn |},
348+
|};
338349

339350
/**
340351
* Usually called `_`, and invoked like `_('Message')` -> `'Nachricht'`.

0 commit comments

Comments
 (0)