1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-15 12:59:09 +00:00
trezor-wallet/src/support/ConnectedIntlProvider.js

78 lines
1.8 KiB
JavaScript
Raw Normal View History

/* @flow */
import * as React from 'react';
import { connect } from 'react-redux';
2019-02-15 19:52:56 +00:00
import type { MapStateToProps } from 'react-redux';
import type { State } from 'flowtype';
import { IntlProvider, addLocaleData } from 'react-intl';
2019-02-13 21:51:54 +00:00
import en from 'react-intl/locale-data/en';
2019-02-13 21:51:54 +00:00
import cs from 'react-intl/locale-data/cs';
import bn from 'react-intl/locale-data/bn';
import de from 'react-intl/locale-data/de';
2019-02-13 21:51:54 +00:00
import el from 'react-intl/locale-data/el';
import es from 'react-intl/locale-data/es';
import fr from 'react-intl/locale-data/fr';
import id from 'react-intl/locale-data/id';
import it from 'react-intl/locale-data/it';
import ja from 'react-intl/locale-data/ja';
import nl from 'react-intl/locale-data/nl';
import pl from 'react-intl/locale-data/pl';
import pt from 'react-intl/locale-data/pt';
import ru from 'react-intl/locale-data/ru';
import uk from 'react-intl/locale-data/uk';
import zh from 'react-intl/locale-data/zh';
2019-03-04 12:33:02 +00:00
addLocaleData([
...en,
...cs,
...bn,
...de,
...el,
...es,
...fr,
...id,
...it,
...ja,
...nl,
...pl,
...pt,
...ru,
...uk,
...zh,
]);
type OwnProps = {
2019-03-04 12:33:02 +00:00
children: React.Node,
};
type StateProps = {
2019-02-15 19:52:56 +00:00
locale: string,
2019-03-04 12:33:02 +00:00
messages: { [string]: string },
};
type Props = StateProps & OwnProps;
2019-03-04 12:33:02 +00:00
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (
state: State
): StateProps => ({
locale: state.wallet.language,
2019-02-15 19:52:56 +00:00
messages: state.wallet.messages,
});
2019-02-15 19:52:56 +00:00
const ReactIntlProvider = ({ children, locale, messages }: Props) => (
<IntlProvider
2019-02-21 13:28:36 +00:00
key={locale} // forces rerender IntlProvider when lang file is downloaded
2019-02-15 19:52:56 +00:00
locale={locale}
messages={messages}
>
{children}
</IntlProvider>
);
2019-03-04 12:33:02 +00:00
export default connect(
mapStateToProps,
null
)(ReactIntlProvider);