mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-25 17:30:37 +01:00
feat(module): support i18n in components (#2553)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
8
src/runtime/composables/defineLocale.ts
Normal file
8
src/runtime/composables/defineLocale.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { Locale, LocalePair } from '../types/locale'
|
||||
|
||||
export function defineLocale(name: string, pair: LocalePair): Locale {
|
||||
return {
|
||||
name,
|
||||
ui: pair
|
||||
}
|
||||
}
|
||||
13
src/runtime/composables/useLocale.ts
Normal file
13
src/runtime/composables/useLocale.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { computed, inject, ref } from 'vue'
|
||||
import type { InjectionKey, Ref } from 'vue'
|
||||
import type { Locale } from '../types/locale'
|
||||
import { buildLocaleContext } from '../utils/locale'
|
||||
import { en } from '../locale'
|
||||
|
||||
export const localeContextInjectionKey: InjectionKey<Ref<Locale | undefined>> = Symbol('nuxt-ui.locale-context')
|
||||
|
||||
export const useLocale = (localeOverrides?: Ref<Locale | undefined>) => {
|
||||
const locale = localeOverrides || inject(localeContextInjectionKey, ref())!
|
||||
|
||||
return buildLocaleContext(computed(() => locale.value || en))
|
||||
}
|
||||
Reference in New Issue
Block a user