umami/pages/_app.js

41 lines
976 B
JavaScript
Raw Normal View History

2020-09-07 08:22:16 +00:00
import React, { useEffect } from 'react';
2020-09-06 00:27:01 +00:00
import { IntlProvider } from 'react-intl';
2020-09-09 03:46:31 +00:00
import { Provider } from 'react-redux';
2020-08-05 05:45:05 +00:00
import { useStore } from 'redux/store';
2020-09-09 03:46:31 +00:00
import useLocale from 'hooks/useLocale';
2020-09-08 02:48:40 +00:00
import { messages } from 'lib/lang';
2020-08-06 02:04:02 +00:00
import 'styles/variables.css';
2020-07-17 08:03:38 +00:00
import 'styles/bootstrap-grid.css';
2020-08-02 04:20:52 +00:00
import 'styles/index.css';
2020-09-07 08:22:16 +00:00
const Intl = ({ children }) => {
2020-09-09 03:46:31 +00:00
const [locale, setLocale] = useLocale();
2020-09-07 08:22:16 +00:00
2020-09-07 22:25:09 +00:00
const Wrapper = ({ children }) => <span className={locale}>{children}</span>;
2020-09-07 08:22:16 +00:00
useEffect(() => {
const saved = localStorage.getItem('locale');
if (saved) {
2020-09-09 03:46:31 +00:00
setLocale(saved);
2020-09-07 08:22:16 +00:00
}
});
return (
2020-09-07 22:25:09 +00:00
<IntlProvider locale={locale} messages={messages[locale]} textComponent={Wrapper}>
2020-09-07 08:22:16 +00:00
{children}
</IntlProvider>
);
};
2020-07-17 08:03:38 +00:00
export default function App({ Component, pageProps }) {
2020-08-05 05:45:05 +00:00
const store = useStore();
return (
2020-09-07 08:22:16 +00:00
<Provider store={store}>
<Intl>
2020-09-06 00:27:01 +00:00
<Component {...pageProps} />
2020-09-07 08:22:16 +00:00
</Intl>
</Provider>
2020-08-05 05:45:05 +00:00
);
2020-07-17 08:03:38 +00:00
}