Skip to content

Commit

Permalink
fix: изменение локали при переключении языка
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegShchavelev committed Oct 7, 2024
1 parent 1a5fd97 commit cd8e6a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from 'vue'
import type { Theme } from 'vitepress'
import { h, watch } from 'vue'
import { useData, type Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'

import AMWDocsAsideMeta from './components/AMWDocsAsideMeta.vue'
Expand Down Expand Up @@ -53,5 +53,15 @@ export default {
app.component('app', AMWApp)
app.component('Video', AMWVideo)
enhanceAppWithTabs(app)
},
setup() {
const { lang } = useData()
watch(
lang,
(val) => {
useI18n.global.locale.value = val
},
{ immediate: true }
)
}
} satisfies Theme
2 changes: 1 addition & 1 deletion .vitepress/theme/plugins/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import { useData } from 'vitepress'

import { AMWThemeLocales } from '../locales/index'

export const useI18n = createI18n({
legacy: false,
locale: 'ru-RU',
messages: AMWThemeLocales
})

0 comments on commit cd8e6a8

Please sign in to comment.