2022-02-13 23:39:27 +08:00
|
|
|
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
2021-02-19 23:23:59 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import * as Setting from "./Setting";
|
2022-12-10 22:14:20 +08:00
|
|
|
import {Dropdown} from "antd";
|
2022-07-10 15:45:55 +08:00
|
|
|
import "./App.less";
|
2023-02-01 22:06:40 +08:00
|
|
|
import {GlobalOutlined} from "@ant-design/icons";
|
2021-07-16 20:24:55 +08:00
|
|
|
|
2022-08-21 22:42:28 -03:00
|
|
|
function flagIcon(country, alt) {
|
|
|
|
return (
|
|
|
|
<img width={24} alt={alt} src={`${Setting.StaticBaseUrl}/flag-icons/${country}.svg`} />
|
|
|
|
);
|
|
|
|
}
|
2021-02-19 23:23:59 +08:00
|
|
|
|
|
|
|
class SelectLanguageBox extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
classes: props,
|
2022-11-19 22:11:19 +08:00
|
|
|
languages: props.languages ?? ["en", "zh", "es", "fr", "de", "ja", "ko", "ru"],
|
2021-02-19 23:23:59 +08:00
|
|
|
};
|
2023-02-01 22:06:40 +08:00
|
|
|
|
|
|
|
Setting.Countries.forEach((country) => {
|
|
|
|
new Image().src = `${Setting.StaticBaseUrl}/flag-icons/${country.country}.svg`;
|
|
|
|
});
|
2021-02-19 23:23:59 +08:00
|
|
|
}
|
|
|
|
|
2022-12-11 04:22:58 +01:00
|
|
|
items = Setting.Countries.map((country) => Setting.getItem(country.label, country.key, flagIcon(country.country, country.alt)));
|
2022-11-19 22:11:19 +08:00
|
|
|
|
|
|
|
getOrganizationLanguages(languages) {
|
|
|
|
const select = [];
|
|
|
|
for (const language of languages) {
|
|
|
|
this.items.map((item, index) => item.key === language ? select.push(item) : null);
|
|
|
|
}
|
|
|
|
return select;
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:23:59 +08:00
|
|
|
render() {
|
2022-11-19 22:11:19 +08:00
|
|
|
const languageItems = this.getOrganizationLanguages(this.state.languages);
|
2022-12-10 22:14:20 +08:00
|
|
|
const onClick = (e) => {
|
|
|
|
Setting.setLanguage(e.key);
|
|
|
|
};
|
2021-07-16 20:24:55 +08:00
|
|
|
|
2021-02-19 23:23:59 +08:00
|
|
|
return (
|
2022-12-10 22:14:20 +08:00
|
|
|
<Dropdown menu={{items: languageItems, onClick}} >
|
2023-02-01 23:11:48 +08:00
|
|
|
<div className="select-box" style={{display: languageItems.length === 0 ? "none" : null, ...this.props.style}} >
|
|
|
|
<GlobalOutlined style={{fontSize: "24px", color: "#4d4d4d"}} />
|
2023-02-01 22:06:40 +08:00
|
|
|
</div>
|
2021-07-16 20:24:55 +08:00
|
|
|
</Dropdown>
|
|
|
|
);
|
2021-02-19 23:23:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SelectLanguageBox;
|