feat(locale): provide dir on defineLocale (#2620)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Alex
2024-11-13 16:19:21 +05:00
committed by GitHub
parent 9c00f7c7b7
commit 937585cb3f
26 changed files with 467 additions and 470 deletions

View File

@@ -3,11 +3,17 @@ import type { InjectionKey, Ref } from 'vue'
import type { Locale } from '../types/locale'
import { buildLocaleContext } from '../utils/locale'
import { en } from '../locale'
import { createSharedComposable } from '@vueuse/core'
export const localeContextInjectionKey: InjectionKey<Ref<Locale | undefined>> = Symbol('nuxt-ui.locale-context')
export const useLocale = (localeOverrides?: Ref<Locale | undefined>) => {
const _useLocale = (localeOverrides?: Ref<Locale | undefined>) => {
const locale = localeOverrides || inject(localeContextInjectionKey, ref())!
/**
* If for some reason the developer does not use `UApp`, we get the language back just in case.
*/
return buildLocaleContext(computed(() => locale.value || en))
}
export const useLocale = createSharedComposable(_useLocale)