2019-11-11 14:10:05 +05:30
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2019-12-07 16:58:52 +05:30
|
|
|
import { RawIntlProvider, IntlShape } from 'react-intl';
|
2019-12-08 00:32:00 +05:30
|
|
|
import i18n from 'app/services/i18n';
|
|
|
|
import { RootState } from 'app/reducers';
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
type Props = {
|
2019-12-07 16:58:52 +05:30
|
|
|
children: React.ReactNode;
|
|
|
|
locale: string;
|
2019-11-11 14:10:05 +05:30
|
|
|
};
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-11 14:10:05 +05:30
|
|
|
function IntlProvider({ children, locale }: Props) {
|
2019-11-27 14:33:32 +05:30
|
|
|
const [intl, setIntl] = useState<IntlShape>(i18n.getIntl());
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
setIntl(await i18n.changeLocale(locale));
|
|
|
|
})();
|
|
|
|
}, [locale]);
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return <RawIntlProvider value={intl}>{children}</RawIntlProvider>;
|
2019-11-11 14:10:05 +05:30
|
|
|
}
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default connect(({ i18n: i18nState }: RootState) => i18nState)(
|
2019-11-27 14:33:32 +05:30
|
|
|
IntlProvider,
|
2019-11-11 14:10:05 +05:30
|
|
|
);
|