add issues Translate

This commit is contained in:
Jackxwb 2024-05-15 16:23:25 +08:00
parent d77e431b97
commit 266c0f9190
5 changed files with 85 additions and 30 deletions

View File

@ -221,6 +221,8 @@
"Template saved": "Template saved",
"Delete diagram": "Delete diagram",
"Are you sure you want to delete this diagram? This operation is irreversible": "Are you sure you want to delete this diagram? This operation is irreversible.",
"Diagrams": "Diagrams",
"Templates": "Templates",
"Untitled diagram": "Untitled diagram",
"Oops! Something went wrong": "Oops! Something went wrong.",
"Oops! Couldn't load diagram": "Oops! Couldn't load diagram",
@ -407,6 +409,30 @@
"Edit type field name to": "Edit type field name to {{val}}",
"Add new type": "Add new type",
"Delete type": "Delete type"
},
"Issues": {
"val": "Issues",
"No issues were detected": "No issues were detected.",
"Duplicate table by the name": "Duplicate table by the name {{name}}",
"Empty field name in table": "Empty field name in table {{name}}",
"Empty field type in table": "Empty field type in table {{name}}",
"noValues": "{{field.name}} field of table {{name}} is of type {{field.type}} but no values have been specified",
"typeNotMatch": "Default value for field \"{{field}}\" in table \"{{table}}\" does not match its type.",
"valNowNull": "\"{{field}}\" field of table \"{{table}}\" is NOT NULL but has default NULL",
"Duplicate table fields in table": "Duplicate table fields in table {{name}}",
"Duplicate index by the name": "Duplicate index by the name {{name}}",
"Empty index type in table": "Empty index type in table {{name}}",
"noPrimaryKey": "Table {{name}} has no primary key",
"TypeNoName": "Declared a type with no name",
"TypeNameDuplicate": "Duplicate types by the name {{name}}",
"EmptyType": "Declared an empty type \"{{name}}\" with no fields",
"Empty field name in type": "Empty field name in type \"{{name}}\"",
"Empty field type in": "Empty field type in {{name}}",
"fieldNoVal": "\"{{field.name}}\" field of type \"{{name}}\" is of type {field.type} but no values have been specified",
"Duplicate type fields in": "Duplicate type fields in {{name}}",
"Duplicate reference by the name": "Duplicate reference by the name {{name}}",
"ReferencingColumnIncompatible": "Referencing column {{columA}} and referenced column {{columB}} are incompatible.",
"Circular relationship involving table": "Circular relationship involving table {{name}}"
}
},
"TableCard": {

View File

@ -221,6 +221,8 @@
"Template saved": "模板保存成功",
"Delete diagram": "删除关系图",
"Are you sure you want to delete this diagram? This operation is irreversible": "您确定要删除此关系图吗?此操作是不可逆的",
"Diagrams": "关系图",
"Templates": "模板",
"Untitled diagram": "无标题关系图",
"Oops! Something went wrong.": "哎呀!出了小问题",
"Oops! Couldn't load diagram": "哎呀!无法加载关系图",
@ -327,7 +329,7 @@
"Table deleted": "表已删除!",
"Type deleted": "类已删除!"
},
"Relationships":{
"Relationships": {
"val": "关系",
"No relationships": "未建立关系",
"Drag to connect fields and form relationships": "拖动可连接字段就能形成关系!",
@ -407,6 +409,30 @@
"Edit type field name to": "自定义类型的字段名称设置为 {{val}}",
"Add new type": "添加新类型",
"Delete type": "删除类型"
},
"Issues": {
"val": "问题",
"No issues were detected": "未检测到任何问题。",
"Duplicate table by the name": "表名称重复 {{name}}",
"Empty field name in table": "表 {{name}} 中有名称为空的字段",
"Empty field type in table": "表 {{name}} 中有类型为空的字段",
"noValues": "表 {{name}} 的 {{field.name}} 字段属于 {{field.type}} 类型,但未指定任何值",
"typeNotMatch": "表\"{{table}}\"的\"{{field}}\"字段设置的默认值与其类型不符",
"valNowNull": "表\"{{table}}\"的\"{{field}}\"字段不能为空但默认值现在是NULL",
"Duplicate table fields in table": "表 {{name}} 中存在重复的字段",
"Duplicate index by the name": "存在多个名称为 {{name}} 的索引",
"Empty index type in table": "表 {{name}} 中的存在没有名字的索引",
"noPrimaryKey": "表 {{name}} 没有主键",
"TypeNoName": "声明了一个没有名称的类型",
"TypeNameDuplicate": "存在多个名称为 {{name}} 自定义类型",
"EmptyType": "声明了一个没有字段的空类型\"{{name}}\"",
"Empty field name in type": "自定义类\"{{name}}\"中的存在名称为空的字段",
"Empty field type in": "自定义类\"{{name}}\"中的存在类型为空的字段",
"fieldNoVal": "自定义类\"{{name}}\"中的\"{{field.name}}\"字段是{{field.type}}类型,您没有指定它的值",
"Duplicate type fields in": "自定义类 {{name}} 中存在重复名称的字段",
"Duplicate reference by the name": "存在多个名为 {{name}} 的索引",
"ReferencingColumnIncompatible": "引用的列 {{columA}} 和引用的列 {{coloB}} 不兼容。",
"Circular relationship involving table": "涉及表 {{name}} 的循环关系"
}
},
"TableCard": {

View File

@ -1536,7 +1536,7 @@ export default function ControlPanel({
onMouseLeave={() => setShowEditName(false)}
onClick={() => setModal(MODAL.RENAME)}
>
{window.name.split(" ")[0] === "t" ? "Templates/" : "Diagrams/"}
{window.name.split(" ")[0] === "t" ? t("Tip.Templates") : t("Tip.Diagrams")}/
{title}
</div>
{(showEditName || modal === MODAL.RENAME) && <IconEdit />}

View File

@ -3,8 +3,10 @@ import { Collapse, Badge } from "@douyinfe/semi-ui";
import { arrayIsEqual } from "../../utils/utils";
import { getIssues } from "../../utils/issues";
import { useSettings, useTables, useTypes } from "../../hooks";
import {useTranslation} from "react-i18next";
export default function Issues() {
const { t } = useTranslation();
const { settings } = useSettings();
const { types } = useTypes();
const { tables, relationships } = useTables();
@ -38,7 +40,7 @@ export default function Issues() {
>
<div className="pe-3 select-none">
<i className="fa-solid fa-triangle-exclamation me-2 text-yellow-500" />
Issues
{t("Page.editor.SidePanel.Issues.val")}
</div>
</Badge>
}
@ -58,7 +60,7 @@ export default function Issues() {
))}
</>
) : (
<div>No issues were detected.</div>
<div>{t("Page.editor.SidePanel.Issues.No issues were detected")}</div>
)}
</div>
</Collapse.Panel>

View File

@ -1,4 +1,5 @@
import { isFunction, strHasQuotes } from "./utils";
import {t} from "i18next";
function validateDateStr(str) {
return /^(?!0000)(?!00)(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[01])|(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31))$/.test(
@ -88,11 +89,11 @@ export function getIssues(diagram) {
diagram.tables.forEach((table) => {
if (table.name === "") {
issues.push(`Declared a table with no name`);
issues.push(t("Page.editor.SidePanel.Issues.No issues were detected"));
}
if (duplicateTableNames[table.name]) {
issues.push(`Duplicate table by the name "${table.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Duplicate table by the name", {name: table.name}));
} else {
duplicateTableNames[table.name] = true;
}
@ -105,33 +106,33 @@ export function getIssues(diagram) {
hasPrimaryKey = true;
}
if (field.name === "") {
issues.push(`Empty field name in table "${table.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Empty field name in table", {name: table.name}));
}
if (field.type === "") {
issues.push(`Empty field type in table "${table.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Empty field type in table", {name: table.name}));
} else if (field.type === "ENUM" || field.type === "SET") {
if (!field.values || field.values.length === 0) {
issues.push(
`"${field.name}" field of table "${table.name}" is of type ${field.type} but no values have been specified`,
t("Page.editor.SidePanel.Issues.noValues", {field: field, name: table.name})
);
}
}
if (!checkDefault(field)) {
issues.push(
`Default value for field "${field.name}" in table "${table.name}" does not match its type.`,
t("Page.editor.SidePanel.Issues.typeNotMatch", {field: field.name, table: table.name})
);
}
if (field.notNull && field.default.toLowerCase() === "null") {
issues.push(
`"${field.name}" field of table "${table.name}" is NOT NULL but has default NULL`,
t("Page.editor.SidePanel.Issues.valNowNull", {field: field.name, table: table.name})
);
}
if (duplicateFieldNames[field.name]) {
issues.push(`Duplicate table fields in table "${table.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Duplicate table fields in table", {name: table.name}));
} else {
duplicateFieldNames[field.name] = true;
}
@ -140,7 +141,7 @@ export function getIssues(diagram) {
const duplicateIndices = {};
table.indices.forEach((index) => {
if (duplicateIndices[index.name]) {
issues.push(`Duplicate index by the name "${index.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Duplicate index by the name", {name: index.name}));
} else {
duplicateIndices[index.name] = true;
}
@ -148,50 +149,50 @@ export function getIssues(diagram) {
table.indices.forEach((index) => {
if (index.fields.length === 0) {
issues.push(`Empty index type in table "${table.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Empty index type in table", {name: table.name}));
}
});
if (!hasPrimaryKey) {
issues.push(`Table "${table.name}" has no primary key`);
issues.push(t("Page.editor.SidePanel.Issues.noPrimaryKey", {name: table.name}));
}
});
const duplicateTypeNames = {};
diagram.types.forEach((type) => {
if (type.name === "") {
issues.push(`Declared a type with no name`);
issues.push(t("Page.editor.SidePanel.Issues.TypeNoName"));
}
if (duplicateTypeNames[type.name]) {
issues.push(`Duplicate types by the name "${type.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.TypeNameDuplicate", {name: type.name}));
} else {
duplicateTypeNames[type.name] = true;
}
if (type.fields.length === 0) {
issues.push(`Declared an empty type "${type.name}" with no fields`);
issues.push(t("Page.editor.SidePanel.Issues.EmptyType", {name: type.name}));
return;
}
const duplicateFieldNames = {};
type.fields.forEach((field) => {
if (field.name === "") {
issues.push(`Empty field name in type "${type.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Empty field name in type", {name: type.name}));
}
if (field.type === "") {
issues.push(`Empty field type in "${type.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Empty field type in", {name: type.name}));
} else if (field.type === "ENUM" || field.type === "SET") {
if (!field.values || field.values.length === 0) {
issues.push(
`"${field.name}" field of type "${type.name}" is of type ${field.type} but no values have been specified`,
t("Page.editor.SidePanel.Issues.fieldNoVal", {field: field, name: type.name})
);
}
}
if (duplicateFieldNames[field.name]) {
issues.push(`Duplicate type fields in "${type.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Duplicate type fields in", {name: type.name}));
} else {
duplicateFieldNames[field.name] = true;
}
@ -201,7 +202,7 @@ export function getIssues(diagram) {
const duplicateFKName = {};
diagram.relationships.forEach((r) => {
if (duplicateFKName[r.name]) {
issues.push(`Duplicate reference by the name "${r.name}"`);
issues.push(t("Page.editor.SidePanel.Issues.Duplicate reference by the name", {name: r.name}));
} else {
duplicateFKName[r.name] = true;
}
@ -210,12 +211,12 @@ export function getIssues(diagram) {
diagram.tables[r.startTableId].fields[r.startFieldId].type !==
diagram.tables[r.endTableId].fields[r.endFieldId].type
) {
issues.push(`Referencing column "${
diagram.tables[r.endTableId].fields[r.endFieldId].name
}" and referenced column "${
diagram.tables[r.startTableId].fields[r.startFieldId].name
}" are incompatible.
`);
issues.push(
t("Page.editor.SidePanel.Issues.ReferencingColumnIncompatible",{
"columA": diagram.tables[r.endTableId].fields[r.endFieldId].name,
"columB": diagram.tables[r.startTableId].fields[r.startFieldId].name
})
);
}
});
@ -224,7 +225,7 @@ export function getIssues(diagram) {
function checkCircularRelationships(tableId, visited = []) {
if (visited.includes(tableId)) {
issues.push(
`Circular relationship involving table: "${diagram.tables[tableId].name}"`,
t("Page.editor.SidePanel.Issues.Circular relationship involving table", {name: diagram.tables[tableId].name})
);
return;
}