2019-11-11 14:10:05 +05:30
|
|
|
// @flow
|
|
|
|
import type { Node } from 'react';
|
|
|
|
import type { IntlShape } from 'react-intl';
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { RawIntlProvider } from 'react-intl';
|
|
|
|
import i18n from 'services/i18n';
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
type OwnProps = {|
|
|
|
|
children: Node
|
|
|
|
|};
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
type Props = {
|
|
|
|
...OwnProps,
|
|
|
|
locale: string
|
|
|
|
};
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
function IntlProvider({ children, locale }: Props) {
|
|
|
|
const [intl, setIntl] = useState<IntlShape>(i18n.getIntl());
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
setIntl(await i18n.changeLocale(locale));
|
|
|
|
})();
|
|
|
|
}, [locale]);
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
return <RawIntlProvider value={intl}>{children}</RawIntlProvider>;
|
|
|
|
}
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
export default connect<Props, OwnProps, _, _, _, _>(({ i18n }) => i18n)(
|
|
|
|
IntlProvider
|
|
|
|
);
|