Skip to content

Commit 3559c40

Browse files
cgsvcgsv
cgsv
authored and
cgsv
committed
add i18n
1 parent d0a5077 commit 3559c40

10 files changed

+255
-38
lines changed

components/Header.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import Github from "./Github";
33
import { useLocalStorage } from "react-use";
44
import { checkOpenaiApiKey } from "@/lib/openai/openai";
55
import { toast, Toaster } from "react-hot-toast";
6+
import { useTranslation } from 'next-i18next';
67

78
export default function Header() {
89
const [userKey, setUserKey] = useLocalStorage<string>("user-openai-apikey-trans");
10+
const {t} = useTranslation("common");
911

1012
const setOpenAIKey = () => {
11-
const key = prompt("Please enter your OpenAI API key (like sk-xxxx )");
13+
const key = prompt(t("Request-Key")!);
1214
if (key && checkOpenaiApiKey(key)) {
1315
setUserKey(key);
14-
toast.success("OpenAI API key successfully set");
16+
toast.success(t("OpenAI API key successfully set"));
1517
} else {
16-
toast.error("OpenAI API key is invalid");
18+
toast.error(t("OpenAI API key is invalid"));
1719
}
1820
}
1921

components/Subtitles.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import SubTitleLine from "./SubtitleLine";
22
import { Node } from "@/lib/srt";
3+
import { useTranslation } from 'next-i18next';
34

45
export default function Subtitles({
56
nodes,
67
transNodes
78
}: {nodes: Node[]; transNodes?: Node[]}) {
9+
const {t} = useTranslation("common");
810
return (
911
<div style={{display: "flex", flexDirection: "column", alignItems: "center"}}>
10-
<SubTitleLine timeStamp={"时间戳"} translation={"译文"} content={"原文"} />
12+
<SubTitleLine timeStamp={t("timestamp")} translation={t("translated")!} content={t("original")} />
1113
{
1214
nodes.map((node, index) => {
1315
let transText;

next-i18next.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
module.exports = {
3+
i18n: {
4+
defaultLocale: 'en',
5+
locales: ['en', 'zh-CN'],
6+
},
7+
}

next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** @type {import('next').NextConfig} */
2+
const {i18n} = require('./next-i18next.config');
3+
24
const nextConfig = {
35
reactStrictMode: true,
6+
i18n,
47
}
58

69
module.exports = nextConfig

package-lock.json

+131
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"eslint-config-next": "13.2.3",
2222
"http-proxy-middleware": "^2.0.6",
2323
"next": "13.2.3",
24+
"next-i18next": "^13.2.1",
2425
"react": "18.2.0",
2526
"react-dom": "18.2.0",
2627
"react-hot-toast": "^2.4.0",

pages/_app.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { Analytics } from "@vercel/analytics/react";
44
import Head from "next/head";
55
import Header from '@/components/Header';
66
import Footer from '@/components/Footer';
7+
import {appWithTranslation} from "next-i18next";
78

8-
export default function App({ Component, pageProps }: AppProps) {
9+
function App({ Component, pageProps }: AppProps) {
910
return (
1011
<div>
1112
<Head>
@@ -20,3 +21,5 @@ export default function App({ Component, pageProps }: AppProps) {
2021
</div>
2122
);
2223
}
24+
25+
export default appWithTranslation(App);

0 commit comments

Comments
 (0)