mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-22 07:50:36 +01:00
feat(useLocale): handle generic messages (#3100)
Co-authored-by: hywax <me@hywax.space> Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import { computed, inject, ref } from 'vue'
|
||||
import { computed, inject, toRef } from 'vue'
|
||||
import type { InjectionKey, Ref } from 'vue'
|
||||
import type { Locale } from '../types/locale'
|
||||
import { createSharedComposable } from '@vueuse/core'
|
||||
import type { Locale, Messages } from '../types/locale'
|
||||
import { buildLocaleContext } from '../utils/locale'
|
||||
import en from '../locale/en'
|
||||
import { createSharedComposable } from '@vueuse/core'
|
||||
|
||||
export const localeContextInjectionKey: InjectionKey<Ref<Locale | undefined>> = Symbol('nuxt-ui.locale-context')
|
||||
export const localeContextInjectionKey: InjectionKey<Ref<Locale<unknown> | undefined>> = Symbol('nuxt-ui.locale-context')
|
||||
|
||||
const _useLocale = (localeOverrides?: Ref<Locale | undefined>) => {
|
||||
const locale = localeOverrides || inject(localeContextInjectionKey, ref())!
|
||||
const _useLocale = (localeOverrides?: Ref<Locale<Messages> | undefined>) => {
|
||||
const locale = localeOverrides || toRef(inject<Locale<Messages>>(localeContextInjectionKey))
|
||||
|
||||
return buildLocaleContext(computed(() => locale.value || en))
|
||||
return buildLocaleContext<Messages>(computed(() => locale.value || en))
|
||||
}
|
||||
|
||||
export const useLocale = createSharedComposable(_useLocale)
|
||||
|
||||
Reference in New Issue
Block a user