Skip to content

Commit

Permalink
feat: fix all i18n support (#63)
Browse files Browse the repository at this point in the history
* feat: add i18n support for rule files

* update: use User-Agent uniformly
  • Loading branch information
love98ooo authored Aug 10, 2024
1 parent c085f09 commit 0dfac51
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 68 deletions.
2 changes: 1 addition & 1 deletion web/src/RecordEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class RecordEditPage extends React.Component {
</Row>
<Row style={{marginTop: "10px"}} >
<Col style={{marginTop: "5px"}} span={2}>
{i18next.t("general:UserAgent")}:
{i18next.t("general:User-Agent")}:
</Col>
<Col span={22} >
<Input value={this.state.record.userAgent} onChange={e => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/RecordListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class RecordListPage extends BaseListPage {
sorter: (a, b) => a.clientIp.localeCompare(b.clientIp),
},
{
title: i18next.t("general:User agent"),
title: i18next.t("general:User-Agent"),
dataIndex: "userAgent",
key: "userAgent",
width: "240px",
Expand Down
14 changes: 7 additions & 7 deletions web/src/RuleEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RuleEditPage extends React.Component {
} style={{marginTop: 10}} type="inner">
<Row style={{marginTop: "20px"}}>
<Col span={2} style={{marginTop: "5px"}}>
{i18next.t("rule:Name")}:
{i18next.t("general:Name")}:
</Col>
<Col span={22}>
<Input value={this.state.rule.name} disabled={true} />
Expand All @@ -96,7 +96,7 @@ class RuleEditPage extends React.Component {
{value: "WAF", text: "WAF"},
{value: "IP", text: "IP"},
{value: "User-Agent", text: "User-Agent"},
{value: "IP Rate Limiting", text: "IP Rate Limiting"},
{value: "IP Rate Limiting", text: i18next.t("rule:IP Rate Limiting")},
// {value: "complex", text: "Complex"},
].map((item, index) => <Option key={index} value={item.value}>{item.text}</Option>)
}
Expand All @@ -105,7 +105,7 @@ class RuleEditPage extends React.Component {
</Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={2}>
Expressions:
{i18next.t("rule:Expressions")}:
</Col>
<Col span={22} >
{
Expand Down Expand Up @@ -144,7 +144,7 @@ class RuleEditPage extends React.Component {
{
this.state.rule.type === "IP Rate Limiting" ? (
<IpRateRuleTable
title={"IP Rate Limiting"}
title={i18next.t("rule:IP Rate Limiting")}
table={this.state.rule.expressions}
ruleName={this.state.rule.name}
account={this.props.account}
Expand All @@ -158,17 +158,17 @@ class RuleEditPage extends React.Component {
this.state.rule.type !== "WAF" && (
<Row style={{marginTop: "20px"}}>
<Col span={2} style={{marginTop: "5px"}}>
{i18next.t("rule:Action")}:
{i18next.t("general:Action")}:
</Col>
<Col span={22}>
<Select virtual={false} value={this.state.rule.action} defaultValue={"Block"} style={{width: "100%"}} onChange={value => {
this.updateRuleField("action", value);
}}>
{
[
{value: "Allow", text: "Allow"},
{value: "Allow", text: i18next.t("rule:Allow")},
// {value: "redirect", text: "Redirect"},
{value: "Block", text: "Block"},
{value: "Block", text: i18next.t("rule:Block")},
// {value: "drop", text: "Drop"},
].map((item, index) => <Option key={index} value={item.value}>{item.text}</Option>)
}
Expand Down
13 changes: 10 additions & 3 deletions web/src/RuleListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,20 @@ class RuleListPage extends BaseListPage {
},
},
{
title: i18next.t("general:Type"),
title: i18next.t("rule:Type"),
dataIndex: "type",
key: "type",
sorter: (a, b) => a.type.localeCompare(b.type),
render: (text, rule, index) => {
return (
<Tag color="blue">
{i18next.t(`rule:${text}`)}
</Tag>
);
},
},
{
title: i18next.t("general:Expressions"),
title: i18next.t("rule:Expressions"),
dataIndex: "expressions",
key: "expressions",
sorter: (a, b) => a.expressions.localeCompare(b.expressions),
Expand Down Expand Up @@ -173,7 +180,7 @@ class RuleListPage extends BaseListPage {
bordered
title={() => (
<div>
{i18next.t("general:Rule")}&nbsp;&nbsp;&nbsp;&nbsp;
{i18next.t("general:Rules")}&nbsp;&nbsp;&nbsp;&nbsp;
<Button type="primary" size="small" onClick={() => this.addRule()}>{i18next.t("general:Add")}</Button>
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/IpRateRuleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class IpRateRuleTable extends React.Component {
renderTable(table) {
const columns = [
{
title: i18next.t("rule:Name"),
title: i18next.t("general:Name"),
dataIndex: "name",
key: "name",
width: "20%",
Expand All @@ -77,7 +77,7 @@ class IpRateRuleTable extends React.Component {
key: "value",
width: "100%",
render: (text, record, index) => (
<InputNumber style={{"width": "100%"}} value={Number(record.value)} addonAfter={i18next.t("rule:seconds")} onChange={e => {
<InputNumber style={{"width": "100%"}} value={Number(record.value)} addonAfter={i18next.t("usage:seconds")} onChange={e => {
this.updateField(table, index, "value", e);
}} />
),
Expand Down
18 changes: 9 additions & 9 deletions web/src/components/IpRuleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import React from "react";
import {DeleteOutlined, DownOutlined, UpOutlined} from "@ant-design/icons";
import {Button, Col, Input, Row, Select, Table, Tooltip} from "antd";
import * as Setting from "../Setting";
import i18next from "i18next";

const {Option} = Select;

Expand Down Expand Up @@ -102,7 +103,7 @@ class IpRuleTable extends React.Component {
renderTable(table) {
const columns = [
{
title: "Name",
title: i18next.t("general:Name"),
dataIndex: "name",
key: "name",
width: "180px",
Expand All @@ -113,7 +114,7 @@ class IpRuleTable extends React.Component {
),
},
{
title: "Operator",
title: i18next.t("rule:Operator"),
dataIndex: "operator",
key: "operator",
width: "180px",
Expand All @@ -123,18 +124,17 @@ class IpRuleTable extends React.Component {
}}>
{
[
{value: "is in", text: "is in"},
{value: "is not in", text: "is not in"},
{value: "is in", text: i18next.t("rule:is in")},
{value: "is not in", text: i18next.t("rule:is not in")},
].map((item, index) => <Option key={index} value={item.value}>{item.text}</Option>)
}
</Select>
),
},
{
title: "Value",
title: i18next.t("rule:IP List"),
dataIndex: "value",
key: "value",
width: "100%",
render: (text, record, index) => (
<Select
mode="tags"
Expand All @@ -147,7 +147,7 @@ class IpRuleTable extends React.Component {
),
},
{
title: "Action",
title: i18next.t("general:Action"),
key: "action",
width: "100px",
render: (text, record, index) => (
Expand All @@ -170,8 +170,8 @@ class IpRuleTable extends React.Component {
title={() => (
<div>
{this.props.title}&nbsp;&nbsp;&nbsp;&nbsp;
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{"Add"}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.restore()}>{"Restore"}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{i18next.t("general:Add")}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.restore()}>{i18next.t("general:Restore")}</Button>
</div>
)}
/>
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/RuleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import React from "react";
import {DeleteOutlined, DownOutlined, UpOutlined} from "@ant-design/icons";
import {Button, Col, Row, Select, Table, Tooltip} from "antd";
import * as Setting from "../Setting";
import i18next from "i18next";

const {Option} = Select;

Expand Down Expand Up @@ -68,7 +69,7 @@ class RuleTable extends React.Component {
renderTable(table) {
const columns = [
{
title: "Name",
title: i18next.t("general:Name"),
dataIndex: "name",
key: "name",
width: "180px",
Expand Down Expand Up @@ -108,7 +109,7 @@ class RuleTable extends React.Component {
title={() => (
<div>
{this.props.title}&nbsp;&nbsp;&nbsp;&nbsp;
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{"Add"}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{i18next.t("general:Add")}</Button>
</div>
)}
/>
Expand Down
15 changes: 7 additions & 8 deletions web/src/components/UaRuleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class UaRuleTable extends React.Component {
renderTable(table) {
const columns = [
{
title: i18next.t("rule:Name"),
title: i18next.t("general:Name"),
dataIndex: "name",
key: "name",
width: "180px",
Expand All @@ -100,11 +100,11 @@ class UaRuleTable extends React.Component {
}}>
{
[
{value: "equals", text: "equals"},
{value: "does not equal", text: "does not equal"},
{value: "contains", text: "contains"},
{value: "does not contain", text: "does not contain"},
{value: "match", text: "regex match"},
{value: "equals", text: i18next.t("rule:equals")},
{value: "does not equal", text: i18next.t("rule:does not equal")},
{value: "contains", text: i18next.t("rule:contains")},
{value: "does not contain", text: i18next.t("rule:does not contain")},
{value: "match", text: i18next.t("rule:regex match")},
].map((item, index) => <Option key={index} value={item.value}>{item.text}</Option>)
}
</Select>
Expand All @@ -114,9 +114,8 @@ class UaRuleTable extends React.Component {
title: i18next.t("rule:Value"),
dataIndex: "value",
key: "value",
width: "100%",
render: (text, record, index) => (
<Input value={text} placeholder="Split with Space" onChange={e => {
<Input value={text} onChange={e => {
this.updateField(table, index, "value", e.target.value);
}} onBlur={e => {
this.updateField(table, index, "value", e.target.value.replace(/\s+/g, " ").trim());
Expand Down
11 changes: 6 additions & 5 deletions web/src/components/WafRuleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import React from "react";
import {DeleteOutlined, DownOutlined, UpOutlined} from "@ant-design/icons";
import {Button, Col, Input, Row, Table, Tooltip} from "antd";
import * as Setting from "../Setting";
import i18next from "i18next";

class WafRuleTable extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -86,7 +87,7 @@ class WafRuleTable extends React.Component {
renderTable(table) {
const columns = [
{
title: "Name",
title: i18next.t("general:Name"),
dataIndex: "name",
key: "name",
width: "180px",
Expand All @@ -99,7 +100,7 @@ class WafRuleTable extends React.Component {
},
},
{
title: "Value",
title: i18next.t("rule:Expression"),
dataIndex: "value",
key: "value",
render: (text, record, index) => {
Expand All @@ -111,7 +112,7 @@ class WafRuleTable extends React.Component {
},
},
{
title: "Action",
title: i18next.t("general:Action"),
key: "action",
width: "100px",
render: (text, record, index) => {
Expand All @@ -137,8 +138,8 @@ class WafRuleTable extends React.Component {
title={() => (
<div>
{this.props.title}&nbsp;&nbsp;&nbsp;&nbsp;
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{"Add"}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.restore()}>{"Restore"}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{i18next.t("general:Add")}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.restore()}>{i18next.t("general:Restore")}</Button>
</div>
)}
/>
Expand Down
31 changes: 28 additions & 3 deletions web/src/locales/de/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"Owner": "Owner",
"Path": "Path",
"Records": "Records",
"Restore": "Restore",
"Rules": "Rules",
"Save": "Save",
"Self": "Self",
"Sites": "Sites",
Expand All @@ -61,9 +63,31 @@
"Top 10 User-Agents": "Top 10 User-Agents",
"Total Request Count": "Total Request Count",
"Unique IP Count": "Unique IP Count",
"User agent": "User agent",
"User-Agent": "User-Agent",
"UserAgent": "UserAgent"
"Update time": "Update time"
},
"rule": {
"Allow": "Allow",
"Block": "Block",
"Block Duration": "Block Duration",
"Edit Rule": "Edit Rule",
"Expression": "Expression",
"Expressions": "Expressions",
"IP List": "IP List",
"IP Rate Limiting": "IP Rate Limiting",
"Operator": "Operator",
"Rate": "Rate",
"Reason": "Reason",
"Status Code": "Status Code",
"Type": "Type",
"Value": "Value",
"contains": "contains",
"does not contain": "does not contain",
"does not equal": "does not equal",
"equals": "equals",
"regex match": "regex match",
"is in": "is in",
"is not in": "is not in"
},
"site": {
"Casdoor app": "Casdoor app",
Expand All @@ -87,6 +111,7 @@
"Day": "Day",
"Hour": "Hour",
"Month": "Month",
"Week": "Week"
"Week": "Week",
"seconds": "seconds"
}
}
Loading

0 comments on commit 0dfac51

Please sign in to comment.