refactor i18n to be server side

This commit is contained in:
Ben Phelps 2022-09-25 19:43:00 +03:00
parent 3ae4113043
commit 8bc240b934
44 changed files with 258 additions and 122 deletions

View file

@ -1,11 +1,12 @@
/* eslint-disable react/jsx-props-no-spreading */
import { SWRConfig } from "swr";
import { appWithTranslation } from "next-i18next";
import "styles/globals.css";
import "styles/theme.css";
import "styles/manrope.css";
import nextI18nextConfig from "../../next-i18next.config";
import "utils/i18n";
import { ColorProvider } from "utils/color-context";
import { ThemeProvider } from "utils/theme-context";
import { SettingsProvider } from "utils/settings-context";
@ -28,4 +29,4 @@ function MyApp({ Component, pageProps }) {
);
}
export default MyApp;
export default appWithTranslation(MyApp, nextI18nextConfig);

View file

@ -2,9 +2,10 @@
import useSWR from "swr";
import Head from "next/head";
import dynamic from "next/dynamic";
import { useTranslation } from "react-i18next";
import { useTranslation } from "next-i18next";
import { useEffect, useContext } from "react";
import { BiError } from "react-icons/bi";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import ServicesGroup from "components/services/group";
import BookmarksGroup from "components/bookmarks/group";
@ -30,7 +31,7 @@ const Version = dynamic(() => import("components/version"), {
const rightAlignedWidgets = ["weatherapi", "openweathermap", "weather", "search", "datetime"];
export function getStaticProps() {
export async function getStaticProps() {
let logger;
try {
logger = createLogger("index");
@ -39,6 +40,7 @@ export function getStaticProps() {
return {
props: {
initialSettings: settings,
...(await serverSideTranslations(settings.language ?? "en")),
},
};
} catch (e) {
@ -48,6 +50,7 @@ export function getStaticProps() {
return {
props: {
initialSettings: {},
...(await serverSideTranslations("en")),
},
};
}