diff --git a/frontend/package.json b/frontend/package.json
index 4652dc7..7b14477 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -36,10 +36,14 @@
"codemirror": "^6.0.1",
"copy-to-clipboard": "^3.3.3",
"html2canvas": "^1.4.1",
+ "i18next": "^23.13.0",
+ "i18next-browser-languagedetector": "^8.0.0",
+ "i18next-http-backend": "^2.5.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-hot-toast": "^2.4.1",
+ "react-i18next": "^15.0.1",
"react-icons": "^4.12.0",
"react-router-dom": "^6.20.1",
"tailwind-merge": "^2.0.0",
diff --git a/frontend/public/locales/en/translation.json b/frontend/public/locales/en/translation.json
new file mode 100644
index 0000000..fd751be
--- /dev/null
+++ b/frontend/public/locales/en/translation.json
@@ -0,0 +1,10 @@
+{
+ "app": {
+ "title": "Screenshot to Code",
+ "errors": {
+ "emptyInstruction": "Please include some instructions for AI on what to update.",
+ "noCurrentVersion": "No current version set. Contact support or open a Github issue.",
+ "invalidHistory": "Version history is invalid. This shouldn't happen. Please contact support or open a Github issue."
+ }
+ }
+}
\ No newline at end of file
diff --git a/frontend/public/locales/zh/translation.json b/frontend/public/locales/zh/translation.json
new file mode 100644
index 0000000..93ac621
--- /dev/null
+++ b/frontend/public/locales/zh/translation.json
@@ -0,0 +1,10 @@
+{
+ "app": {
+ "title": "截图转代码",
+ "errors": {
+ "emptyInstruction": "请为AI提供一些关于更新内容的指示。",
+ "noCurrentVersion": "未设置当前版本。请联系支持或在Github上开issue。",
+ "invalidHistory": "版本历史无效。这不应该发生。请联系支持或在Github上开issue。"
+ }
+ }
+}
\ No newline at end of file
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 9c20df3..be98d1a 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -23,8 +23,11 @@ import DeprecationMessage from "./components/messages/DeprecationMessage";
import { GenerationSettings } from "./components/settings/GenerationSettings";
import StartPane from "./components/start-pane/StartPane";
import { takeScreenshot } from "./lib/takeScreenshot";
+import { useTranslation } from 'react-i18next'; // 导入 useTranslation hook
function App() {
+ const { t } = useTranslation(); // 初始化 useTranslation hook
+
const {
// Inputs
inputMode,
@@ -118,16 +121,14 @@ function App() {
const regenerate = () => {
if (currentVersion === null) {
- toast.error(
- "No current version set. Please open a Github issue as this shouldn't happen."
- );
+ toast.error(t('app.errors.noCurrentVersion'));
return;
}
// Retrieve the previous command
const previousCommand = appHistory[currentVersion];
if (previousCommand.type !== "ai_create") {
- toast.error("Only the first version can be regenerated.");
+ toast.error(t('app.errors.regenerateFirstVersion'));
return;
}
@@ -189,9 +190,7 @@ function App() {
setAppHistory((prev) => {
// Validate parent version
if (parentVersion === null) {
- toast.error(
- "No parent version set. Contact support or open a Github issue."
- );
+ toast.error(t('app.errors.noCurrentVersion'));
return prev;
}
@@ -254,14 +253,12 @@ function App() {
selectedElement?: HTMLElement
) {
if (updateInstruction.trim() === "") {
- toast.error("Please include some instructions for AI on what to update.");
+ toast.error(t('app.errors.emptyInstruction'));
return;
}
if (currentVersion === null) {
- toast.error(
- "No current version set. Contact support or open a Github issue."
- );
+ toast.error(t('app.errors.noCurrentVersion'));
return;
}
@@ -269,9 +266,7 @@ function App() {
try {
historyTree = extractHistoryTree(appHistory, currentVersion);
} catch {
- toast.error(
- "Version history is invalid. This shouldn't happen. Please contact support or open a Github issue."
- );
+ toast.error(t('app.errors.invalidHistory'));
return;
}
@@ -365,7 +360,7 @@ function App() {