Skip to content

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

feat(i18n): enabled i18n for naive-ui (#222)

Luke Zhou4071b8a70f3e
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index dce1ee5770..1868d3d47b 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -1,20 +1,26 @@
<template>
- <BBModalStack>
- <KBarWrapper>
- <router-view />
- <template v-if="state.notificationList.length > 0">
- <BBNotification
- :placement="'BOTTOM_RIGHT'"
- :notification-list="state.notificationList"
- @close="removeNotification"
- />
- </template>
- </KBarWrapper>
- </BBModalStack>
+ <!-- it is recommended by naive-ui that we leave the local to null when the language is en -->
+ <n-config-provider
+ :locale="isZhCn ? zhCN : null"
+ :date-locale="isZhCn ? dateZhCN : null"
+ >
+ <BBModalStack>
+ <KBarWrapper>
+ <router-view />
+ <template v-if="state.notificationList.length > 0">
+ <BBNotification
+ :placement="'BOTTOM_RIGHT'"
+ :notification-list="state.notificationList"
+ @close="removeNotification"
+ />
+ </template>
+ </KBarWrapper>
+ </BBModalStack>
+ </n-config-provider>
</template>
<script lang="ts">
-import { reactive, watchEffect, onErrorCaptured } from "vue";
+import { reactive, watchEffect, onErrorCaptured, computed } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { isDev } from "./utils";
@@ -22,6 +28,8 @@ import { Notification } from "./types";
import { BBNotificationItem } from "./bbkit/types";
import KBarWrapper from "./components/KBar/KBarWrapper.vue";
import BBModalStack from "./bbkit/BBModalStack.vue";
+import { useLanguage } from "./composables/useLanguage";
+import { NConfigProvider, zhCN, dateZhCN } from "naive-ui";
// Show at most 3 notifications to prevent excessive notification when shit hits the fan.
const MAX_NOTIFICATION_DISPLAY_COUNT = 3;
@@ -42,16 +50,23 @@ export default {
components: {
KBarWrapper,
BBModalStack,
+ NConfigProvider,
},
setup() {
const store = useStore();
const router = useRouter();
+ const { locale } = useLanguage();
const state = reactive<LocalState>({
notificationList: [],
prevLoggedIn: store.getters["auth/isLoggedIn"](),
});
+ // for now, we only support two languages
+ const isZhCn = computed(() => {
+ return locale.value === "zh-CN";
+ });
+
setInterval(() => {
const loggedIn = store.getters["auth/isLoggedIn"]();
if (state.prevLoggedIn != loggedIn) {
@@ -124,6 +139,9 @@ export default {
return {
state,
+ isZhCn,
+ zhCN,
+ dateZhCN,
removeNotification,
};
},