From e301121c214664cb7bbbb3fdd2e90cb3cdbd2b20 Mon Sep 17 00:00:00 2001
From: RobotHuang <1183598761@qq.com>
Date: Fri, 19 Feb 2021 23:23:59 +0800
Subject: [PATCH] feat: support i18n
Signed-off-by: RobotHuang <1183598761@qq.com>
---
conf/app.conf | 2 +-
web/package.json | 4 +-
web/src/App.js | 23 +++++++-----
web/src/ApplicationEditPage.js | 21 ++++++-----
web/src/ApplicationListPage.js | 21 ++++++-----
web/src/OrganizationEditPage.js | 13 ++++---
web/src/OrganizationListPage.js | 19 +++++-----
web/src/ProviderEditPage.js | 19 +++++-----
web/src/ProviderListPage.js | 23 ++++++------
web/src/SelectLanguageBox.js | 38 +++++++++++++++++++
web/src/Setting.js | 16 ++++++++
web/src/UserEditPage.js | 33 +++++++++--------
web/src/UserListPage.js | 31 ++++++++--------
web/src/basic/HomePage.js | 9 +++--
web/src/i18n.js | 39 +++++++++++++++++++
web/src/locales/en.json | 64 ++++++++++++++++++++++++++++++++
web/src/locales/zh.json | 66 +++++++++++++++++++++++++++++++++
web/yarn.lock | 34 +++++++++++++++++
18 files changed, 373 insertions(+), 102 deletions(-)
create mode 100644 web/src/SelectLanguageBox.js
create mode 100644 web/src/i18n.js
create mode 100644 web/src/locales/en.json
create mode 100644 web/src/locales/zh.json
diff --git a/conf/app.conf b/conf/app.conf
index 999319d8..f54b7136 100644
--- a/conf/app.conf
+++ b/conf/app.conf
@@ -3,7 +3,7 @@ httpport = 8000
runmode = dev
SessionOn = true
copyrequestbody = true
-dataSourceName = root:123@tcp(localhost:3306)/
+dataSourceName = root:123456@tcp(localhost:3306)/
dbName = casdoor
AuthState = "casdoor"
UseProxy = false
\ No newline at end of file
diff --git a/web/package.json b/web/package.json
index 6144d780..252798a8 100644
--- a/web/package.json
+++ b/web/package.json
@@ -8,16 +8,18 @@
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"antd": "^4.7.2",
+ "i18next": "^19.8.9",
"moment": "^2.29.1",
"react": "^16.14.0",
"react-device-detect": "^1.14.0",
"react-dom": "^16.14.0",
"react-github-corner": "^2.5.0",
+ "react-i18next": "^11.8.7",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3"
},
"scripts": {
- "start": "set PORT=7001 && react-scripts start",
+ "start": "PORT=7001 && export PORT=7001 && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
diff --git a/web/src/App.js b/web/src/App.js
index 2f84d9e5..78e29452 100644
--- a/web/src/App.js
+++ b/web/src/App.js
@@ -35,6 +35,8 @@ import Face from "./auth/Face";
import LoginPage from "./auth/LoginPage";
import * as AuthBackend from "./auth/AuthBackend";
import AuthCallback from "./auth/AuthCallback";
+import SelectLanguageBox from './SelectLanguageBox';
+import i18next from 'i18next';
const { Header, Footer } = Layout;
@@ -56,6 +58,7 @@ class App extends Component {
}
componentWillMount() {
+ Setting.setLanguage();
this.updateMenuKey();
this.getAccount();
}
@@ -127,11 +130,11 @@ class App extends Component {
);
@@ -162,14 +165,14 @@ class App extends Component {
res.push(
- Register
+ {i18next.t("account:Register")}
);
res.push(
- Login
+ {i18next.t("account:Login")}
);
@@ -190,7 +193,7 @@ class App extends Component {
res.push(
- Home
+ {i18next.t("general:Home")}
);
@@ -199,33 +202,32 @@ class App extends Component {
res.push(
- Organizations
+ {i18next.t("general:Organizations")}
);
res.push(
- Users
+ {i18next.t("general:Users")}
);
res.push(
- Providers
+ {i18next.t("general:Providers")}
);
res.push(
- Applications
+ {i18next.t("general:Applications")}
);
}
-
return res;
}
@@ -305,6 +307,7 @@ class App extends Component {
textAlign: 'center',
}
}>
+
Made with ❤️ by Casbin
)
diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js
index 9e3dd6ec..b154a46a 100644
--- a/web/src/ApplicationEditPage.js
+++ b/web/src/ApplicationEditPage.js
@@ -20,6 +20,7 @@ import * as Setting from "./Setting";
import * as ProviderBackend from "./backend/ProviderBackend";
import * as OrganizationBackend from "./backend/OrganizationBackend";
import Face from "./auth/Face";
+import i18next from "i18next";
const { Option } = Select;
@@ -89,13 +90,13 @@ class ApplicationEditPage extends React.Component {
return (
- Edit Application
-
+ {i18next.t("application:Edit Application")}
+
} style={{marginLeft: '5px'}} type="inner">
- Name:
+ {i18next.t("general:Name")}:
{
@@ -105,7 +106,7 @@ class ApplicationEditPage extends React.Component {
- Display Name:
+ {i18next.t("general:Display Name")}:
{
@@ -130,7 +131,7 @@ class ApplicationEditPage extends React.Component {
- Preview:
+ {i18next.t("general:Preview")}:
@@ -142,7 +143,7 @@ class ApplicationEditPage extends React.Component {
- Organization:
+ {i18next.t("general:Organization")}:
- Enable Password:
+ {i18next.t("application:Enable Password")}:
{
@@ -164,7 +165,7 @@ class ApplicationEditPage extends React.Component {
- Providers:
+ {i18next.t("general:Providers")}: