Add option to select a default language
This commit is contained in:
parent
15a8c4f0d7
commit
29792bc35f
@ -1,17 +1,26 @@
|
|||||||
/* eslint-disable react/jsx-props-no-spreading */
|
/* eslint-disable react/jsx-props-no-spreading */
|
||||||
import { SWRConfig } from "swr";
|
import useSWR, { SWRConfig } from "swr";
|
||||||
|
|
||||||
import "styles/globals.css";
|
import "styles/globals.css";
|
||||||
import "styles/weather-icons.css";
|
import "styles/weather-icons.css";
|
||||||
import "styles/theme.css";
|
import "styles/theme.css";
|
||||||
|
|
||||||
import "utils/i18n";
|
import i18n from "utils/i18n";
|
||||||
|
|
||||||
|
const swr = (resource, init) => fetch(resource, init).then((res) => res.json());
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }) {
|
function MyApp({ Component, pageProps }) {
|
||||||
|
const { data } = useSWR(`/api/settings`, swr);
|
||||||
|
console.log(data);
|
||||||
|
if (data?.language) {
|
||||||
|
console.log("custom language");
|
||||||
|
i18n.changeLanguage(data.language);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SWRConfig
|
<SWRConfig
|
||||||
value={{
|
value={{
|
||||||
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
|
fetcher: swr,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Component {...pageProps} />
|
<Component {...pageProps} />
|
||||||
|
|||||||
7
src/pages/api/settings.js
Normal file
7
src/pages/api/settings.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { getSettings } from "utils/config";
|
||||||
|
|
||||||
|
export default async function handler(req, res) {
|
||||||
|
const settings = await getSettings();
|
||||||
|
|
||||||
|
return res.send(settings);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user