From 19ba37e0c2d3798aa091821cbaad635be027a546 Mon Sep 17 00:00:00 2001
From: Yaodong Yu <2814461814@qq.com>
Date: Sat, 19 Nov 2022 22:11:19 +0800
Subject: [PATCH] feat: can specify available UI languages for an organization
(#1306)
---
object/init.go | 1 +
object/organization.go | 1 +
web/src/App.js | 4 ++--
web/src/App.less | 6 -----
web/src/OrganizationEditPage.js | 25 +++++++++++++++++++++
web/src/OrganizationListPage.js | 1 +
web/src/SelectLanguageBox.js | 39 +++++++++++++++++++++++----------
web/src/Setting.js | 7 ------
web/src/auth/LoginPage.js | 6 ++---
web/src/auth/SignupPage.js | 2 +-
web/src/locales/de/data.json | 2 ++
web/src/locales/en/data.json | 2 ++
web/src/locales/fr/data.json | 2 ++
web/src/locales/ja/data.json | 2 ++
web/src/locales/ko/data.json | 2 ++
web/src/locales/ru/data.json | 2 ++
web/src/locales/zh/data.json | 2 ++
17 files changed, 75 insertions(+), 31 deletions(-)
diff --git a/object/init.go b/object/init.go
index b7d51489..cc2a4868 100644
--- a/object/init.go
+++ b/object/init.go
@@ -58,6 +58,7 @@ func initBuiltInOrganization() bool {
PhonePrefix: "86",
DefaultAvatar: fmt.Sprintf("%s/img/casbin.svg", conf.GetConfigString("staticBaseUrl")),
Tags: []string{},
+ Languages: []string{"en", "zh", "es", "fr", "de", "ja", "ko", "ru"},
AccountItems: []*AccountItem{
{Name: "Organization", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
{Name: "ID", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
diff --git a/object/organization.go b/object/organization.go
index 9315f61c..19ea752f 100644
--- a/object/organization.go
+++ b/object/organization.go
@@ -45,6 +45,7 @@ type Organization struct {
DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"`
DefaultApplication string `xorm:"varchar(100)" json:"defaultApplication"`
Tags []string `xorm:"mediumtext" json:"tags"`
+ Languages []string `xorm:"varchar(255)" json:"languages"`
MasterPassword string `xorm:"varchar(100)" json:"masterPassword"`
EnableSoftDeletion bool `json:"enableSoftDeletion"`
IsProfilePublic bool `json:"isProfilePublic"`
diff --git a/web/src/App.js b/web/src/App.js
index 7b26dd69..f9b67887 100644
--- a/web/src/App.js
+++ b/web/src/App.js
@@ -636,7 +636,7 @@ class App extends Component {
{
this.renderAccount()
}
-
+ {this.state.account && }
@@ -680,7 +680,7 @@ class App extends Component {
{
this.renderAccount()
}
-
+ {this.state.account && }
{
diff --git a/web/src/App.less b/web/src/App.less
index a1f34018..c8df7432 100644
--- a/web/src/App.less
+++ b/web/src/App.less
@@ -59,12 +59,6 @@
height: 70px; /* Footer height */
}
-#language-box-corner {
- position: absolute;
- top: 75px;
- right: 0;
-}
-
.language-box {
background: url("@{StaticBaseUrl}/img/muti_language.svg");
background-size: 25px, 25px;
diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js
index 879a143c..00dc3876 100644
--- a/web/src/OrganizationEditPage.js
+++ b/web/src/OrganizationEditPage.js
@@ -255,6 +255,31 @@ class OrganizationEditPage extends React.Component {
}} />
+
+
+ {Setting.getLabel(i18next.t("general:Languages"), i18next.t("general:Languages - Tooltip"))} :
+
+
+
+
+
{Setting.getLabel(i18next.t("organization:Soft deletion"), i18next.t("organization:Soft deletion - Tooltip"))} :
diff --git a/web/src/OrganizationListPage.js b/web/src/OrganizationListPage.js
index a77701d0..523aa002 100644
--- a/web/src/OrganizationListPage.js
+++ b/web/src/OrganizationListPage.js
@@ -37,6 +37,7 @@ class OrganizationListPage extends BaseListPage {
defaultAvatar: `${Setting.StaticBaseUrl}/img/casbin.svg`,
defaultApplication: "",
tags: [],
+ languages: ["en", "zh", "es", "fr", "de", "ja", "ko", "ru"],
masterPassword: "",
enableSoftDeletion: false,
isProfilePublic: true,
diff --git a/web/src/SelectLanguageBox.js b/web/src/SelectLanguageBox.js
index 5770ff41..1490b19d 100644
--- a/web/src/SelectLanguageBox.js
+++ b/web/src/SelectLanguageBox.js
@@ -28,28 +28,45 @@ class SelectLanguageBox extends React.Component {
super(props);
this.state = {
classes: props,
+ languages: props.languages ?? ["en", "zh", "es", "fr", "de", "ja", "ko", "ru"],
};
}
+ items = [
+ this.getItem("English", "en", flagIcon("US", "English")),
+ this.getItem("简体中文", "zh", flagIcon("CN", "简体中文")),
+ this.getItem("Español", "es", flagIcon("ES", "Español")),
+ this.getItem("Français", "fr", flagIcon("FR", "Français")),
+ this.getItem("Deutsch", "de", flagIcon("DE", "Deutsch")),
+ this.getItem("日本語", "ja", flagIcon("JP", "日本語")),
+ this.getItem("한국어", "ko", flagIcon("KR", "한국어")),
+ this.getItem("Русский", "ru", flagIcon("RU", "Русский")),
+ ];
+
+ getOrganizationLanguages(languages) {
+ const select = [];
+ for (const language of languages) {
+ this.items.map((item, index) => item.key === language ? select.push(item) : null);
+ }
+ return select;
+ }
+
+ getItem(label, key, icon) {
+ return {key, icon, label};
+ }
+
render() {
+ const languageItems = this.getOrganizationLanguages(this.state.languages);
const menu = (
-