diff --git a/front/components/Navbar.vue b/front/components/Navbar.vue index f72349d..affc036 100644 --- a/front/components/Navbar.vue +++ b/front/components/Navbar.vue @@ -1,33 +1,91 @@ \ No newline at end of file + { + key: "about", + icon: () => + h("img", { + class: "size-10 rounded-full border-2 border-white/50", + src: "/logo.png", + }), + onClick: () => { + router.push("/about"); + }, + isActive: (item: { key: string }) => route.path?.endsWith(item.key), + className: "!p-1.5", + }, + { name: t("navbar.file"), key: "file", icon: LucidePaperclip }, + { name: t("navbar.text"), key: "text", icon: LucideClipboardType }, + { + key: "i18n", + icon: LucideGlobe, + onClick: () => { + showDrawer({ + render: () => h(I18nSwitchDrawer), + }); + }, + className: "size-12 !p-1.5 justify-center items-center", + }, +]; +const route = useRoute(); +const router = useRouter(); +const type = computed(() => route?.query?.type); + +const isActive = (item: { + key: string; + isActive?: (item: { key: string }) => boolean; +}) => { + const { key, isActive } = item || {}; + return isActive ? isActive(item) : type.value === key; +}; + +const handleClick = (item: { key: string; onClick?: () => void }) => { + const { key, onClick } = item || {}; + if (onClick) { + onClick(); + return; + } + router.push({ + path: "/", + query: { + ...route.query, + type: key, + }, + }); +}; + diff --git a/front/i18n/locales/en.json b/front/i18n/locales/en.json new file mode 100644 index 0000000..3ace311 --- /dev/null +++ b/front/i18n/locales/en.json @@ -0,0 +1,9 @@ +{ + "navbar": { + "file": "File", + "text": "Text" + }, + "i18n": { + "switchLocale": "Switch Language" + } +} diff --git a/front/i18n/locales/zh-CN.json b/front/i18n/locales/zh-CN.json new file mode 100644 index 0000000..4e5bd83 --- /dev/null +++ b/front/i18n/locales/zh-CN.json @@ -0,0 +1,9 @@ +{ + "navbar": { + "file": "文件", + "text": "文本" + }, + "i18n": { + "switchLocale": "切换语言" + } +} diff --git a/front/nuxt.config.ts b/front/nuxt.config.ts index eb8911b..625ed83 100644 --- a/front/nuxt.config.ts +++ b/front/nuxt.config.ts @@ -5,15 +5,25 @@ export default defineNuxtConfig({ devtools: { enabled: true }, css: ["~/assets/css/main.css"], modules: [ - "@vueuse/nuxt", // '@serwist/nuxt', + // '@serwist/nuxt', + "@vueuse/nuxt", "motion-v/nuxt", "nuxt-lucide-icons", "shadcn-nuxt", "@vee-validate/nuxt", "@pinia/nuxt", "@nuxt/image", + "@nuxtjs/i18n", ], // serwist: {}, + i18n: { + strategy: "no_prefix", + defaultLocale: "en", + locales: [ + { code: "zh-CN", name: "中文(简体)", file: "zh-CN.json" }, + { code: "en", name: "English", file: "en.json" }, + ], + }, vite: { plugins: [tailwindcss()], }, diff --git a/front/package.json b/front/package.json index d7e1670..e9094f2 100644 --- a/front/package.json +++ b/front/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "@nuxt/image": "1.10.0", + "@nuxtjs/i18n": "9.5.5", "@pinia/nuxt": "^0.11.0", "@tailwindcss/postcss": "^4.1.3", "@tailwindcss/vite": "^4.1.3",