diff --git a/next-i18next.config.js b/next-i18next.config.js index 0514681..89bd601 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -1,5 +1,3 @@ -// @ts-check - /** * @type {import('next-i18next').UserConfig} */ diff --git a/renderer/components/Nav.tsx b/renderer/components/Nav.tsx index d4fa089..9f59c06 100644 --- a/renderer/components/Nav.tsx +++ b/renderer/components/Nav.tsx @@ -16,10 +16,10 @@ import { useTranslation } from "next-i18next"; import Ipc from "../lib/ipc"; -const Nav = ({ current, isLogined, locale }) => { +const Nav = ({ current, isLogined }) => { console.log("isLogined:", isLogined); - const { t } = useTranslation("common"); + const { t, i18n: {language: locale} } = useTranslation("common"); const [userState, setUserState] = useState(null); const metas = [ @@ -35,6 +35,10 @@ const Nav = ({ current, isLogined, locale }) => { name: t("Settings"), href: "/settings", }, + // { + // name: 'Stream', + // href: "/stream?serverid=123", + // }, ]; useEffect(() => { diff --git a/renderer/components/TitleModal.tsx b/renderer/components/TitleModal.tsx index 0bf3604..76e749b 100644 --- a/renderer/components/TitleModal.tsx +++ b/renderer/components/TitleModal.tsx @@ -15,7 +15,7 @@ const XCLOUD_PREFIX = "xcloud_"; function TitleModal(props) { const router = useRouter(); - const { t } = useTranslation('cloud'); + const { t, i18n: {language: locale} } = useTranslation('cloud'); const titleItem = props.title || {}; @@ -27,7 +27,10 @@ function TitleModal(props) { const handleStartGame = () => { console.log("titleItem:", titleItem); const titleId = titleItem.titleId || titleItem.XCloudTitleId; - router.push("stream/" + XCLOUD_PREFIX + titleId); + router.push({ + pathname: `/${locale}/stream`, + query: { serverid: XCLOUD_PREFIX + titleId } + }); }; return ( diff --git a/renderer/lib/get-static.ts b/renderer/lib/get-static.ts new file mode 100644 index 0000000..f8637ed --- /dev/null +++ b/renderer/lib/get-static.ts @@ -0,0 +1,32 @@ +import {serverSideTranslations} from "next-i18next/serverSideTranslations" + +import i18next from "../../next-i18next.config.js" + +export function getI18nPaths() { + return ["en", "zh"].map(locale => ({ + params: { + locale, + }, + })) +} + +export function getStaticPaths() { + return { + fallback: false, paths: getI18nPaths(), + } +} + +export async function getI18nProperties(context, namespaces = ["common"]) { + const locale = context?.params?.locale ?? i18next.i18n.defaultLocale; + return { + ...(await serverSideTranslations(locale, namespaces)), + } +} + +export function makeStaticProperties(namespaces = []) { + return async function (context) { + return { + props: await getI18nProperties(context, namespaces), + }; + }; +} \ No newline at end of file diff --git a/renderer/next.config.js b/renderer/next.config.js index 3091fdc..9463d40 100644 --- a/renderer/next.config.js +++ b/renderer/next.config.js @@ -1,7 +1,5 @@ -const { i18n } = require('../next-i18next.config.js') - +/** @type {import('next').NextConfig} */ module.exports = { - // i18n, webpack: (config, { isServer }) => { if (!isServer) { // config.target = 'electron-renderer'; @@ -10,6 +8,7 @@ module.exports = { return config; }, + trailingSlash: true, images: { unoptimized: true, diff --git a/renderer/pages/404.tsx b/renderer/pages/404.tsx deleted file mode 100644 index 5696b3b..0000000 --- a/renderer/pages/404.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react' -import Head from 'next/head' - -function Error404Page() { - return ( - - - XStreaming - Error - - -

Oopsie 404.. Action not found

-
- ) -} - -export default Error404Page diff --git a/renderer/pages/500.tsx b/renderer/pages/500.tsx deleted file mode 100644 index b8fe488..0000000 --- a/renderer/pages/500.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react' -import Head from 'next/head' - -function Error500Page() { - return ( - - - XStreaming - Error - - -

Oopsie 500.. Application has an error

-
- ) -} - -export default Error500Page diff --git a/renderer/pages/[locale]/404.tsx b/renderer/pages/[locale]/404.tsx new file mode 100644 index 0000000..8711a6b --- /dev/null +++ b/renderer/pages/[locale]/404.tsx @@ -0,0 +1,23 @@ +import React from "react"; +import Head from "next/head"; +import { getStaticPaths, makeStaticProperties } from "../../lib/get-static"; + +function Error404Page() { + return ( + + + XStreaming - Error + + +

Oopsie 404.. Action not found

+
+ ); +} + +export default Error404Page; + +// eslint-disable-next-line react-refresh/only-export-components +export const getStaticProps = makeStaticProperties(["common"]); + +// eslint-disable-next-line react-refresh/only-export-components +export { getStaticPaths }; diff --git a/renderer/pages/[locale]/500.tsx b/renderer/pages/[locale]/500.tsx new file mode 100644 index 0000000..4810474 --- /dev/null +++ b/renderer/pages/[locale]/500.tsx @@ -0,0 +1,23 @@ +import React from "react"; +import Head from "next/head"; +import { getStaticPaths, makeStaticProperties } from "../../lib/get-static"; + +function Error500Page() { + return ( + + + XStreaming - Error + + +

Oopsie 500.. Application has an error

+
+ ); +} + +export default Error500Page; + +// eslint-disable-next-line react-refresh/only-export-components +export const getStaticProps = makeStaticProperties(["common"]); + +// eslint-disable-next-line react-refresh/only-export-components +export { getStaticPaths }; diff --git a/renderer/pages/home.tsx b/renderer/pages/[locale]/home.tsx similarity index 88% rename from renderer/pages/home.tsx rename to renderer/pages/[locale]/home.tsx index 72954ad..3790dcb 100644 --- a/renderer/pages/home.tsx +++ b/renderer/pages/[locale]/home.tsx @@ -9,19 +9,18 @@ import { } from "@nextui-org/react"; import { useTranslation } from "next-i18next"; import { useRouter } from 'next/router'; -import Layout from "../components/Layout"; -import AuthModal from "../components/AuthModal"; -import Ipc from "../lib/ipc"; -import Loading from "../components/Loading"; -import Nav from "../components/Nav"; +import Layout from "../../components/Layout"; +import AuthModal from "../../components/AuthModal"; +import Ipc from "../../lib/ipc"; +import Loading from "../../components/Loading"; +import Nav from "../../components/Nav"; import Image from "next/image"; -import type { GetStaticProps } from 'next' -import { serverSideTranslations } from 'next-i18next/serverSideTranslations' +import { getStaticPaths, makeStaticProperties } from "../../lib/get-static"; function Home() { - const { t } = useTranslation('home'); + const { t, i18n: {language: locale} } = useTranslation('home'); const router = useRouter(); const [loading, setLoading] = useState(false); @@ -130,12 +129,15 @@ function Home() { const startSession = (sessionId) => { console.log("sessionId:", sessionId); - router.push(router.locale + "/stream/" + sessionId); + router.push({ + pathname: `/${locale}/stream`, + query: { serverid: sessionId } + }); }; return ( <> -