mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
feat(docs): check browser language
This commit is contained in:
parent
9be508c976
commit
c3b22c1b27
10 changed files with 220 additions and 242 deletions
|
@ -1,14 +1,8 @@
|
|||
import { defineConfig } from 'vitepress'
|
||||
import { sharedConfig } from './shared'
|
||||
import { enConfig } from "./en"
|
||||
import { zhCNConfig } from "./zh_CN"
|
||||
import { zhTWConfig } from "./zh_TW";
|
||||
import locales from './locales'
|
||||
|
||||
export default defineConfig({
|
||||
...sharedConfig,
|
||||
locales: {
|
||||
root: { label: 'English', lang: 'en', ...enConfig },
|
||||
zh_CN: { label: '简体中文', lang: 'zh-CN', ...zhCNConfig },
|
||||
zh_TW: { label: '繁體中文', lang: 'zh-TW', ...zhTWConfig }
|
||||
}
|
||||
locales
|
||||
})
|
||||
|
|
11
docs/.vitepress/config/locales.ts
Normal file
11
docs/.vitepress/config/locales.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import {enConfig} from './en'
|
||||
import {zhCNConfig} from './zh_CN'
|
||||
import {zhTWConfig} from './zh_TW'
|
||||
|
||||
const locales = {
|
||||
root: { label: 'English', lang: 'en', ...enConfig },
|
||||
'zh_CN': { label: '简体中文', lang: 'zh-CN', ...zhCNConfig },
|
||||
'zh_TW': { label: '繁體中文', lang: 'zh-TW', ...zhTWConfig }
|
||||
}
|
||||
|
||||
export default locales
|
|
@ -73,7 +73,7 @@ export const zhTWConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||
provider: 'local',
|
||||
options: {
|
||||
locales: {
|
||||
zh_CN: {
|
||||
zh_TW: {
|
||||
translations: {
|
||||
button: {
|
||||
buttonText: '搜尋文件',
|
||||
|
|
|
@ -1,10 +1,32 @@
|
|||
<script setup>
|
||||
import DefaultTheme from 'vitepress/theme'
|
||||
const { Layout } = DefaultTheme
|
||||
import {useData, useRoute, useRouter} from 'vitepress'
|
||||
import {onMounted} from 'vue'
|
||||
import locales from '../config/locales'
|
||||
|
||||
const {Layout} = DefaultTheme
|
||||
|
||||
const {lang} = useData()
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
onMounted(async () => {
|
||||
const language = (
|
||||
navigator.language
|
||||
).replaceAll('-', '_')
|
||||
|
||||
if (lang.value === 'en'
|
||||
&& locales[language]
|
||||
&& !route.path.includes(language)
|
||||
) {
|
||||
await router.go(language + '/' + route.path)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Layout />
|
||||
<Layout/>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue