commit 0a48cad65b67356325a7312af58e16d9dd4fc81f
parent 2b29a91eb423741c1f0e8a3a7117758f49b1515f
Author: MTRNord <mtrnord1@gmail.com>
Date: Mon, 31 Jan 2022 01:57:53 +0100
Make sure we always have the SSR translations set up
Diffstat:
5 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/pages/login.tsx b/pages/login.tsx
@@ -1,3 +1,5 @@
+import { GetServerSideProps } from "next";
+import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import Head from "next/head";
import Link from "next/link";
import { NextRouter, withRouter } from "next/router";
@@ -196,4 +198,14 @@ class Login extends PureComponent<Props, State> {
}
Login.contextType = ClientContext;
+
+
+export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
+ return {
+ props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
+ }
+ };
+};
+
export default withRouter(Login);
\ No newline at end of file
diff --git a/pages/logout.tsx b/pages/logout.tsx
@@ -1,3 +1,5 @@
+import { GetServerSideProps } from "next";
+import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { NextRouter, withRouter } from "next/router";
import { PureComponent } from "react";
import { ClientContext } from "../components/ClientContext";
@@ -31,4 +33,13 @@ class Logout extends PureComponent<Props, State> {
}
Logout.contextType = ClientContext;
+
+export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
+ return {
+ props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
+ }
+ };
+};
+
export default withRouter(Logout);
\ No newline at end of file
diff --git a/pages/post/[id].tsx b/pages/post/[id].tsx
@@ -18,6 +18,7 @@ import Link from 'next/link';
import Footer from '../../components/Footer';
import { Blurhash } from 'react-blurhash';
import User from '../../helpers/db/Users';
+import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
type Props = InferGetServerSidePropsType<typeof getServerSideProps> & {
router: NextRouter;
@@ -443,8 +444,7 @@ class Post extends PureComponent<Props, State> {
Post.contextType = ClientContext;
-export const getServerSideProps: GetServerSideProps = async (context) => {
- const { query, res } = context;
+export const getServerSideProps: GetServerSideProps = async ({ res, locale, query }) => {
const event_id = decodeURIComponent(query.id as string);
res.setHeader(
@@ -462,6 +462,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
console.error("Failed to register as guest:", error);
return {
props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
directory_data: JSON.stringify(data),
event_id: event_id,
hasFullyLoaded: false,
@@ -484,6 +485,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const profile = await client.getProfile(image_event.sender);
return {
props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
image_event: image_event as MatrixImageEvents,
event_id: event_id,
hasFullyLoaded: true,
@@ -495,6 +497,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
console.debug(`Failed to fetch profile for user ${image_event.sender}:`, error);
return {
props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
image_event: image_event as MatrixImageEvents,
event_id: event_id,
hasFullyLoaded: true,
@@ -504,10 +507,18 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
}
}
} catch {
- return { notFound: true, props: {} };
+ return {
+ notFound: true, props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
+ }
+ };
}
}
- return { notFound: true, props: {} };
+ return {
+ notFound: true, props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
+ }
+ };
};
export default withRouter(Post);
\ No newline at end of file
diff --git a/pages/profile/[userid].tsx b/pages/profile/[userid].tsx
@@ -1,4 +1,5 @@
import { GetServerSideProps, InferGetServerSidePropsType } from "next";
+import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import Head from "next/head";
import Link from "next/link";
import { NextRouter, withRouter } from "next/router";
@@ -339,7 +340,7 @@ class Profile extends PureComponent<Props, State> {
Profile.contextType = ClientContext;
export const getServerSideProps: GetServerSideProps = async (context) => {
- const { query, res } = context;
+ const { query, res, locale } = context;
const mxid = decodeURIComponent(query.userid as string);
res.setHeader(
@@ -350,14 +351,23 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
try {
return {
props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
mxid: mxid
}
};
} catch {
- return { notFound: true, props: {} };
+ return {
+ notFound: true, props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
+ }
+ };
}
}
- return { notFound: true, props: {} };
+ return {
+ notFound: true, props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
+ }
+ };
};
diff --git a/pages/submit.tsx b/pages/submit.tsx
@@ -1,3 +1,5 @@
+import { GetServerSideProps } from "next";
+import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import Head from "next/head";
import { NextRouter, withRouter } from "next/router";
import { PureComponent, ReactNode } from "react";
@@ -127,4 +129,12 @@ class Submit extends PureComponent<Props, State> implements DropCallbacks {
Submit.contextType = ClientContext;
+export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
+ return {
+ props: {
+ ...(await serverSideTranslations(locale || 'en', ['common'])),
+ }
+ };
+};
+
export default withRouter(Submit);
\ No newline at end of file