Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: iterate i18n key in sequential order (#11474)

Tianzhou (天舟)a0acc84c16c4
diff --git a/frontend/i18n.ts b/frontend/i18n.ts
index c2542a670c..b53275d41e 100644
--- a/frontend/i18n.ts
+++ b/frontend/i18n.ts
@@ -1,6 +1,5 @@
import { config } from "dotenv";
import { promises as fs } from "fs";
-import { basename } from "path";
// Create a file .env.i18n and add
// GOOGLE_TRANSLATE_API_KEY=xxxx
@@ -118,31 +117,29 @@ async function addMissingKeysFromSource(
const merged: JsonObject = {};
const keys = new Set([...Object.keys(source), ...Object.keys(target)]);
- keys.forEach((key) => {
- (async () => {
- if (key in source && !(key in target)) {
- // Key exists in source but not in target
- merged[key] = await translateJsonValue(source[key], lang);
- } else if (
- key in source &&
- key in target &&
- typeof source[key] === "object" &&
- !Array.isArray(source[key]) &&
- typeof target[key] === "object" &&
- !Array.isArray(target[key])
- ) {
- // Both have the key and its value is an object, merge recursively
- merged[key] = await addMissingKeysFromSource(
- source[key] as JsonObject,
- target[key] as JsonObject,
- lang
- );
- } else {
- // Key exists in target or both, prefer target's value
- merged[key] = target[key];
- }
- })();
- });
+ for (const key of keys) {
+ if (key in source && !(key in target)) {
+ // Key exists in source but not in target
+ merged[key] = await translateJsonValue(source[key], lang);
+ } else if (
+ key in source &&
+ key in target &&
+ typeof source[key] === "object" &&
+ !Array.isArray(source[key]) &&
+ typeof target[key] === "object" &&
+ !Array.isArray(target[key])
+ ) {
+ // Both have the key and its value is an object, merge recursively
+ merged[key] = await addMissingKeysFromSource(
+ source[key] as JsonObject,
+ target[key] as JsonObject,
+ lang
+ );
+ } else {
+ // Key exists in target or both, prefer target's value
+ merged[key] = target[key];
+ }
+ }
return merged;
}
@@ -165,7 +162,7 @@ async function updateLocalizationFiles() {
await saveJsonFile(langFile, updatedData);
const langSQLReviewFile = `src/locales/sql-review/${lang}.json`;
- const targetSQLReviewData = await loadJsonFile(langFile);
+ const targetSQLReviewData = await loadJsonFile(langSQLReviewFile);
const updatedSQLReviewData = await addMissingKeysFromSource(
sourceSQLReviewData,
targetSQLReviewData,
diff --git a/frontend/package.json b/frontend/package.json
index b8177dee08..e0ec5bdfe4 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -17,7 +17,7 @@
"test": "vitest run --passWithNoTests",
"coverage": "vitest --coverage",
"postinstall": "npm run copy:monaco-workers && monaco-treemending",
- "i18n": "ts-node i18n.ts"
+ "i18n": "TS_NODE_PROJECT='./tsconfig.i18n.json' ts-node i18n.ts"
},
"dependencies": {
"@bytebase/vue-kbar": "0.1.8",
diff --git a/frontend/tsconfig.i18n.json b/frontend/tsconfig.i18n.json
new file mode 100644
index 0000000000..755bf42286
--- /dev/null
+++ b/frontend/tsconfig.i18n.json
@@ -0,0 +1,6 @@
+{
+ "compilerOptions": {
+ // To allow iterating Set<string> with for...of and calling async translating API in sequential order.
+ "target": "ES2015"
+ }
+}