support icu messageformat for translations
This commit is contained in:
parent
b5c514e1d1
commit
6d56f8b8aa
35 changed files with 839 additions and 104 deletions
|
@ -3,11 +3,17 @@
|
|||
|
||||
import React from 'react';
|
||||
|
||||
import type { FormatXMLElementFn } from 'intl-messageformat';
|
||||
import type { LocalizerType, RenderTextCallbackType } from '../types/Util';
|
||||
import type { ReplacementValuesType } from '../types/I18N';
|
||||
import * as log from '../logging/log';
|
||||
import { strictAssert } from '../util/assert';
|
||||
|
||||
export type FullJSXType = Array<JSX.Element | string> | JSX.Element | string;
|
||||
export type FullJSXType =
|
||||
| FormatXMLElementFn<JSX.Element | string>
|
||||
| Array<JSX.Element | string>
|
||||
| JSX.Element
|
||||
| string;
|
||||
export type IntlComponentsType =
|
||||
| undefined
|
||||
| Array<FullJSXType>
|
||||
|
@ -32,7 +38,7 @@ export class Intl extends React.Component<Props> {
|
|||
index: number,
|
||||
placeholderName: string,
|
||||
key: number
|
||||
): FullJSXType | null {
|
||||
): JSX.Element | null {
|
||||
const { id, components } = this.props;
|
||||
|
||||
if (!components) {
|
||||
|
@ -75,6 +81,15 @@ export class Intl extends React.Component<Props> {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (!i18n.isLegacyFormat(id)) {
|
||||
strictAssert(
|
||||
!Array.isArray(components),
|
||||
`components cannot be an array for ICU message ${id}`
|
||||
);
|
||||
const intl = i18n.getIntl();
|
||||
return intl.formatMessage({ id }, components);
|
||||
}
|
||||
|
||||
const text = i18n(id);
|
||||
const results: Array<
|
||||
string | JSX.Element | Array<string | JSX.Element> | null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue