Skip to content

Commit

Permalink
dayjs localization (not yet working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Tilsch committed Mar 25, 2024
1 parent d1898b6 commit c620908
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion apps/exhibition-live/components/i18n/getStaticPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
const locales = ["en", "de"];
import 'dayjs/locale/de';
import 'dayjs/locale/en';
import dayjs from "dayjs";
export const getI18nPaths = () =>
locales.map((lng) => ({
params: {
Expand All @@ -22,7 +25,8 @@ export const mixinStaticPathsParams = (paths) =>
.flat();

export async function getI18nProps(ctx, ns = ["translation", "table"]) {
const locale = ctx?.params?.locale;
const locale = ctx?.params?.locale || "en";
dayjs.locale(locale);
let props = {
...(await serverSideTranslations(locale, ns)),
};
Expand Down
1 change: 0 additions & 1 deletion apps/exhibition-live/pages/[locale]/list/[typeName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function getStaticProps(ctx) {
};
}
export default (props: Props) => {
const router = useRouter();
const { t } = useTranslation();
const { typeName } = props;
const title = `${t(typeName)} - ${t("list")}`
Expand Down
11 changes: 10 additions & 1 deletion apps/exhibition-live/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ import ThemeComponent from "../components/theme/ThemeComponent";
import NiceModal from "@ebay/nice-modal-react";
import { SnackbarProvider } from "notistack";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { appWithTranslation, UserConfig } from "next-i18next";
import {appWithTranslation, UserConfig, useTranslation} from "next-i18next";
import nextI18NextConfig from "../next-i18next.config";
import { GoogleOAuthProvider } from "@react-oauth/google";
import { AdbProvider } from "../components/provider/adbContext";
import {LocalizationProvider} from "@mui/x-date-pickers";
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import dayjs from "dayjs";
import 'dayjs/locale/de';
import 'dayjs/locale/en';
import {useEffect} from "react";


export const queryClient = new QueryClient();
const QueryClientProviderWrapper = ({
Expand All @@ -33,6 +38,10 @@ const QueryClientProviderWrapper = ({
);
};
function App({ Component, pageProps }: AppProps) {
const { i18n } = useTranslation()
useEffect(() => {
dayjs.locale(i18n.language in ["en", "de"] ? i18n.language : "en")
}, [i18n.language]);
return (
<QueryClientProviderWrapper>
<LocalizationProvider dateAdapter={AdapterDayjs}>
Expand Down

0 comments on commit c620908

Please sign in to comment.