mirror of
https://github.com/drawdb-io/drawdb.git
synced 2026-02-12 02:00:40 +08:00
Configure i18n and add simplified chinese (#99)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import i18n from "../i18n/i18n";
|
||||
import { isFunction, strHasQuotes } from "./utils";
|
||||
|
||||
function validateDateStr(str) {
|
||||
@@ -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(i18n.t("table_w_no_name"));
|
||||
}
|
||||
|
||||
if (duplicateTableNames[table.name]) {
|
||||
issues.push(`Duplicate table by the name "${table.name}"`);
|
||||
issues.push(i18n.t("duplicate_table_by_name", { tableName: table.name }));
|
||||
} else {
|
||||
duplicateTableNames[table.name] = true;
|
||||
}
|
||||
@@ -105,33 +106,48 @@ export function getIssues(diagram) {
|
||||
hasPrimaryKey = true;
|
||||
}
|
||||
if (field.name === "") {
|
||||
issues.push(`Empty field name in table "${table.name}"`);
|
||||
issues.push(i18n.t("empty_field_name", { tableName: table.name }));
|
||||
}
|
||||
|
||||
if (field.type === "") {
|
||||
issues.push(`Empty field type in table "${table.name}"`);
|
||||
issues.push(i18n.t("empty_field_type", { tableName: 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`,
|
||||
i18n.t("no_values_for_field", {
|
||||
tableName: table.name,
|
||||
fieldName: field.name,
|
||||
type: field.type,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!checkDefault(field)) {
|
||||
issues.push(
|
||||
`Default value for field "${field.name}" in table "${table.name}" does not match its type.`,
|
||||
i18n.t("default_doesnt_match_type", {
|
||||
tableName: table.name,
|
||||
fieldName: field.name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (field.notNull && field.default.toLowerCase() === "null") {
|
||||
issues.push(
|
||||
`"${field.name}" field of table "${table.name}" is NOT NULL but has default NULL`,
|
||||
i18n.t("not_null_is_null", {
|
||||
tableName: table.name,
|
||||
fieldName: field.name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (duplicateFieldNames[field.name]) {
|
||||
issues.push(`Duplicate table fields in table "${table.name}"`);
|
||||
issues.push(
|
||||
i18n.t("duplicate_fields", {
|
||||
tableName: table.name,
|
||||
fieldName: field.name,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
duplicateFieldNames[field.name] = true;
|
||||
}
|
||||
@@ -140,7 +156,12 @@ 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(
|
||||
i18n.t("duplicate_index", {
|
||||
tableName: table.name,
|
||||
indexName: index.name,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
duplicateIndices[index.name] = true;
|
||||
}
|
||||
@@ -148,50 +169,69 @@ export function getIssues(diagram) {
|
||||
|
||||
table.indices.forEach((index) => {
|
||||
if (index.fields.length === 0) {
|
||||
issues.push(`Empty index type in table "${table.name}"`);
|
||||
issues.push(
|
||||
i18n.t("empty_index", {
|
||||
tableName: table.name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasPrimaryKey) {
|
||||
issues.push(`Table "${table.name}" has no primary key`);
|
||||
issues.push(i18n.t("no_primary_key", { tableName: table.name }));
|
||||
}
|
||||
});
|
||||
|
||||
const duplicateTypeNames = {};
|
||||
diagram.types.forEach((type) => {
|
||||
if (type.name === "") {
|
||||
issues.push(`Declared a type with no name`);
|
||||
issues.push(i18n.t("type_with_no_name"));
|
||||
}
|
||||
|
||||
if (duplicateTypeNames[type.name]) {
|
||||
issues.push(`Duplicate types by the name "${type.name}"`);
|
||||
issues.push(i18n.t("duplicate_types", { typeName: 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(i18n.t("type_w_no_fields", { typeName: type.name }));
|
||||
return;
|
||||
}
|
||||
|
||||
const duplicateFieldNames = {};
|
||||
type.fields.forEach((field) => {
|
||||
if (field.name === "") {
|
||||
issues.push(`Empty field name in type "${type.name}"`);
|
||||
issues.push(
|
||||
i18n.t("empty_type_field_name", {
|
||||
typeName: type.name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (field.type === "") {
|
||||
issues.push(`Empty field type in "${type.name}"`);
|
||||
issues.push(
|
||||
i18n.t("empty_type_field_type", {
|
||||
typeName: 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`,
|
||||
i18n.t("no_values_for_type_field", {
|
||||
typeName: type.name,
|
||||
fieldName: field.name,
|
||||
type: field.type,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (duplicateFieldNames[field.name]) {
|
||||
issues.push(`Duplicate type fields in "${type.name}"`);
|
||||
i18n.t("duplicate_type_fields", {
|
||||
typeName: type.name,
|
||||
fieldName: field.name,
|
||||
});
|
||||
} else {
|
||||
duplicateFieldNames[field.name] = true;
|
||||
}
|
||||
@@ -201,22 +241,14 @@ 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(
|
||||
i18n.t("duplicate_reference", {
|
||||
refName: r.name,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
duplicateFKName[r.name] = true;
|
||||
}
|
||||
|
||||
if (
|
||||
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.
|
||||
`);
|
||||
}
|
||||
});
|
||||
|
||||
const visitedTables = new Set();
|
||||
@@ -224,7 +256,9 @@ export function getIssues(diagram) {
|
||||
function checkCircularRelationships(tableId, visited = []) {
|
||||
if (visited.includes(tableId)) {
|
||||
issues.push(
|
||||
`Circular relationship involving table: "${diagram.tables[tableId].name}"`,
|
||||
i18n.t("circular_dependency", {
|
||||
refName: diagram.tables[tableId].name,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
import { MODAL } from "../data/constants";
|
||||
import i18n from "../i18n/i18n";
|
||||
|
||||
export const getModalTitle = (modal) => {
|
||||
switch (modal) {
|
||||
case MODAL.IMPORT:
|
||||
case MODAL.IMPORT_SRC:
|
||||
return "Import diagram";
|
||||
return i18n.t("import_diagram");
|
||||
case MODAL.CODE:
|
||||
return "Export source";
|
||||
return i18n.t("export_source");
|
||||
case MODAL.IMG:
|
||||
return "Export image";
|
||||
return i18n.t("export_image");
|
||||
case MODAL.RENAME:
|
||||
return "Rename diagram";
|
||||
return i18n.t("rename_diagram");
|
||||
case MODAL.OPEN:
|
||||
return "Open diagram";
|
||||
return i18n.t("open_diagram");
|
||||
case MODAL.SAVEAS:
|
||||
return "Save as";
|
||||
return i18n.t("save_as");
|
||||
case MODAL.NEW:
|
||||
return "Create new diagram";
|
||||
return i18n.t("create_new_diagram");
|
||||
case MODAL.TABLE_WIDTH:
|
||||
return "Set the table width";
|
||||
return i18n.t("table_width");
|
||||
case MODAL.LANGUAGE:
|
||||
return i18n.t("language");
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
@@ -28,19 +31,19 @@ export const getOkText = (modal) => {
|
||||
switch (modal) {
|
||||
case MODAL.IMPORT:
|
||||
case MODAL.IMPORT_SRC:
|
||||
return "Import";
|
||||
return i18n.t("import");
|
||||
case MODAL.CODE:
|
||||
case MODAL.IMG:
|
||||
return "Export";
|
||||
return i18n.t("export");
|
||||
case MODAL.RENAME:
|
||||
return "Rename";
|
||||
return i18n.t("rename");
|
||||
case MODAL.OPEN:
|
||||
return "Open";
|
||||
return i18n.t("open");
|
||||
case MODAL.SAVEAS:
|
||||
return "Save as";
|
||||
return i18n.t("save_as");
|
||||
case MODAL.NEW:
|
||||
return "Create";
|
||||
return i18n.t("create");
|
||||
default:
|
||||
return "Confirm";
|
||||
return i18n.t("confirm");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user