import { Localized, LocalizationProvider, withLocalization, GetString } from 'fluent-react';
import { FluentBundle, ftl } from 'fluent';
import * as ReactDOM from 'react-dom';
// Localized examples:
const Test = () => (
Hello, world!
);
// LocalizationProvider examples:
function* generateBundles(currentLocales: string[]) {
for (const locale of currentLocales) {
const bundle = new FluentBundle(locale);
bundle.addMessages(ftl`some-message = Hello`);
yield bundle;
}
}
ReactDOM.render(
Content
,
document.getElementById('root')
);
// withLocalization examples:
interface Props {
getString: GetString;
otherProp: number;
someOtherProp: string;
}
function HelloButton(props: Props) {
const { getString } = props;
return (
);
}
const LocalizedHelloButton = withLocalization(HelloButton);
// Remove `getString` from list of required props:
const Test2 = () => (
);
// Should not allow `getString` prop:
const Test3 = () => (
// $ExpectError
{}}/>
);
// Should not allow any other props to be omitted:
const Test4 = () => (
// $ExpectError
);