Skip to content

Commit

Permalink
support market i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 14, 2023
1 parent b1ae79e commit 5f4e87b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 9 additions & 1 deletion .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineAsyncComponent } from 'vue'
import Markdown from 'marked-vue'
import Schema from 'schemastery'
import components from '@koishijs/components'
import Layout from './layout.vue'
import { createI18n } from 'vue-i18n'
import {
ElButton,
ElCheckbox,
Expand All @@ -25,6 +25,7 @@ import {
ElTimePicker,
ElTooltip,
} from 'element-plus'
import Layout from './layout.vue'

import '@koishijs/core'
import 'element-plus/dist/index.css'
Expand All @@ -41,6 +42,12 @@ export default defineTheme({
},
Layout,
enhanceApp({ app }) {
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
fallbackLocale: 'zh-CN',
})

app.use(components)
app.use(ElButton)
app.use(ElCheckbox)
Expand All @@ -61,6 +68,7 @@ export default defineTheme({
app.use(ElSwitch)
app.use(ElTimePicker)
app.use(ElTooltip)
app.use(i18n)
app.component('k-markdown', Markdown)
},
})
10 changes: 8 additions & 2 deletions .vitepress/theme/layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
import { Layout } from '@koishijs/vitepress/client'
import { useData } from 'vitepress'
import { computed } from 'vue'
import { computed, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { getSorted, MarketFilter } from '@koishijs/market'
import VPNavBarTitle from '@theme-default/components/VPNavBarTitle.vue'
import VPSidebarItem from '@theme-default/components/VPSidebarItem.vue'
import { home, market, words } from './utils'
const { frontmatter, theme } = useData()
const { frontmatter, localeIndex, theme } = useData()
const composer = useI18n()
watch(localeIndex, () => {
composer.locale.value = localeIndex.value
}, { immediate: true })
const navItem = computed(() => ({
text: theme.value.navText || '导航',
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vitepress build ."
},
"devDependencies": {
"@koishijs/components": "^1.0.5",
"@koishijs/components": "^1.1.0",
"@koishijs/core": "^4.12.8",
"@koishijs/market": "^3.0.1",
"@koishijs/market": "^3.1.0",
"@koishijs/registry": "^4.6.1",
"@koishijs/vitepress": "^2.1.3",
"@types/node": "^18.16.0",
"@koishijs/vitepress": "^2.2.0",
"@types/node": "^18.16.9",
"@types/spark-md5": "^3.0.2",
"cross-env": "^7.0.3",
"element-plus": "2.3.4",
"koishi": "^4.12.8",
"marked-vue": "^1.2.3",
"typescript": "^5.0.4",
"vitepress": "1.0.0-alpha.73"
"vitepress": "1.0.0-alpha.73",
"vue-i18n": "^9.2.2"
}
}

0 comments on commit 5f4e87b

Please sign in to comment.