Add option to select a default language

This commit is contained in:
Chris McGravey 2022-09-14 18:59:54 -05:00
parent 15a8c4f0d7
commit 29792bc35f
2 changed files with 19 additions and 3 deletions

View file

@ -1,17 +1,26 @@
/* eslint-disable react/jsx-props-no-spreading */
import { SWRConfig } from "swr";
import useSWR, { SWRConfig } from "swr";
import "styles/globals.css";
import "styles/weather-icons.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 }) {
const { data } = useSWR(`/api/settings`, swr);
console.log(data);
if (data?.language) {
console.log("custom language");
i18n.changeLanguage(data.language);
}
return (
<SWRConfig
value={{
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
fetcher: swr,
}}
>
<Component {...pageProps} />

View 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);
}