feat(locale): provide code (#2611)

This commit is contained in:
Alex
2024-11-12 16:57:40 +05:00
committed by GitHub
parent 30218f1b5b
commit 8a8b1ee2e1
16 changed files with 45 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ export type Translator = (path: string, option?: TranslatorOption) => string
export type LocaleContext = {
locale: Ref<Locale>
lang: Ref<string>
code: Ref<string>
t: Translator
}
@@ -27,10 +28,12 @@ export function translate(path: string, option: undefined | TranslatorOption, lo
export function buildLocaleContext(locale: MaybeRef<Locale>): LocaleContext {
const lang = computed(() => unref(locale).name)
const code = computed(() => unref(locale).code)
const localeRef = isRef(locale) ? locale : ref(locale)
return {
lang,
code,
locale: localeRef,
t: buildTranslator(locale)
}