Skip to content

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

chore: add `i18n` to guide (#1712)

boojack3ad5e5893c05
diff --git a/frontend/src/composables/useLanguage.ts b/frontend/src/composables/useLanguage.ts
index 27f6adb8ae..e7828e81b7 100644
--- a/frontend/src/composables/useLanguage.ts
+++ b/frontend/src/composables/useLanguage.ts
@@ -1,6 +1,7 @@
import { useI18n } from "vue-i18n";
import { useLocalStorage } from "@vueuse/core";
import { useRouter } from "vue-router";
+import { emitStorageChangedEvent } from "@/utils";
/**
* Language hook for i18n
@@ -18,6 +19,8 @@ const useLanguage = () => {
language: lang,
},
};
+ emitStorageChangedEvent();
+
if (currentRoute.value.meta.title) {
const title = currentRoute.value.meta.title(currentRoute.value);
document.title = title || "Bytebase";
diff --git a/frontend/src/plugins/demo/guide.ts b/frontend/src/plugins/demo/guide.ts
index 4f77450cab..d7f17ee0cb 100644
--- a/frontend/src/plugins/demo/guide.ts
+++ b/frontend/src/plugins/demo/guide.ts
@@ -3,10 +3,12 @@ import {
checkUrlPathnameMatched,
getElementBounding,
getElementMaxZIndex,
+ isNullOrUndefined,
waitForTargetElement,
} from "./utils";
import * as storage from "./storage";
import { GuideData, GuidePosition, StepData } from "./types";
+import { getStringFromI18NText, nextI18NText } from "./i18n";
// validateStepData will check if the step data is valid
export const validateStepData = (stepData: StepData) => {
@@ -15,11 +17,11 @@ export const validateStepData = (stepData: StepData) => {
return false;
}
// title is required
- if (typeof stepData.title !== "string") {
+ if (isNullOrUndefined(stepData.title)) {
return false;
}
// description is required
- if (typeof stepData.description !== "string") {
+ if (isNullOrUndefined(stepData.description)) {
return false;
}
@@ -91,11 +93,11 @@ const renderGuideDialog = (
const titleElement = document.createElement("p");
titleElement.className = "bb-guide-title-text";
- titleElement.innerText = title;
+ titleElement.innerText = getStringFromI18NText(title);
guideDialogDiv.appendChild(titleElement);
const descriptionElement = document.createElement("p");
descriptionElement.className = "bb-guide-description-text";
- descriptionElement.innerText = description;
+ descriptionElement.innerText = getStringFromI18NText(description);
guideDialogDiv.appendChild(descriptionElement);
if (!guideStep.hideNextButton) {
@@ -106,7 +108,7 @@ const renderGuideDialog = (
if (stepIndex === guideData.steps.length - 1) {
nextButton.innerText = "Done";
} else {
- nextButton.innerText = "Next";
+ nextButton.innerText = getStringFromI18NText(nextI18NText);
}
buttonsContainer.appendChild(nextButton);
guideDialogDiv.appendChild(buttonsContainer);
diff --git a/frontend/src/plugins/demo/i18n.ts b/frontend/src/plugins/demo/i18n.ts
new file mode 100644
index 0000000000..9d863611f9
--- /dev/null
+++ b/frontend/src/plugins/demo/i18n.ts
@@ -0,0 +1,25 @@
+import { head } from "lodash-es";
+import * as storage from "./storage";
+import { I18NText } from "./types";
+
+export const nextI18NText = {
+ "en-US": "Next",
+ "zh-CN": "下一步",
+};
+
+export const getStringFromI18NText = (text: string | I18NText) => {
+ if (typeof text === "string") {
+ return text;
+ }
+
+ const values = Object.values(text);
+ const firstValue = head(values) || "";
+ const { bytebase_options: BBOptions } = storage.get(["bytebase_options"]);
+
+ if (BBOptions && BBOptions.appearance) {
+ const language = BBOptions.appearance.language;
+ return text[language] || firstValue;
+ }
+
+ return firstValue;
+};
diff --git a/frontend/src/plugins/demo/storage.ts b/frontend/src/plugins/demo/storage.ts
index 14cb2b5331..9f81454045 100644
--- a/frontend/src/plugins/demo/storage.ts
+++ b/frontend/src/plugins/demo/storage.ts
@@ -6,6 +6,11 @@ interface StorageData {
name: string;
stepIndex: number;
};
+ bytebase_options: {
+ appearance: {
+ language: string;
+ };
+ };
}
type StorageKey = keyof StorageData;
diff --git a/frontend/src/plugins/demo/types.ts b/frontend/src/plugins/demo/types.ts
index 2afd7604b0..7da05982f3 100644
--- a/frontend/src/plugins/demo/types.ts
+++ b/frontend/src/plugins/demo/types.ts
@@ -2,10 +2,14 @@ type StepType = "click" | "change";
export type GuidePosition = "bottom" | "top" | "left" | "right";
+export type I18NText = {
+ [key: string]: string;
+};
+
export interface StepData {
type: StepType;
- title: string;
- description: string;
+ title: string | I18NText;
+ description: string | I18NText;
selectors: string[][];
// url is using for validate url in change step
url?: string;
diff --git a/frontend/src/plugins/demo/utils.ts b/frontend/src/plugins/demo/utils.ts
index 28fbbd7f45..c0445cb7d5 100644
--- a/frontend/src/plugins/demo/utils.ts
+++ b/frontend/src/plugins/demo/utils.ts
@@ -137,3 +137,7 @@ export const checkUrlPathnameMatched = (url: string) => {
const urlObject = new URL(url);
return urlObject.pathname === window.location.pathname;
};
+
+export const isNullOrUndefined = (value: any) => {
+ return value === null || value === undefined;
+};
diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts
index 9391f915e1..13306cc68a 100644
--- a/frontend/src/utils/util.ts
+++ b/frontend/src/utils/util.ts
@@ -172,3 +172,13 @@ export function defer<T = any>() {
});
return d;
}
+
+// emitStorageChangedEvent is used to notify the storage changed event
+export function emitStorageChangedEvent() {
+ const iframeEl = document.createElement("iframe");
+ iframeEl.style.display = "none";
+ document.body.appendChild(iframeEl);
+
+ iframeEl.contentWindow?.localStorage.setItem("t", Date.now().toString());
+ iframeEl.remove();
+}
diff --git a/frontend/static/demo/schema-migration/guide.json b/frontend/static/demo/schema-migration/guide.json
index 9dd70102ed..a526437b79 100644
--- a/frontend/static/demo/schema-migration/guide.json
+++ b/frontend/static/demo/schema-migration/guide.json
@@ -3,8 +3,14 @@
{},
{},
{
- "title": "Click the Alter Schema button",
- "description": "Alter schema is a main feature of Bytebase",
+ "title": {
+ "en-US": "Click the Alter Schema button",
+ "zh-CN": "点击修改模式按钮"
+ },
+ "description": {
+ "en-US": "Alter schema is a main feature of Bytebase",
+ "zh-CN": "修改数据库 Schema 是 Bytebase 的核心功能之一"
+ },
"selectors": [["[data-label='bb-alter-schema-button']"]],
"url": "http://localhost:3000"
},