Files
AstralRinth/packages/ui/src/providers/i18n.ts
Calum H. a903e46be9 feat: remove nuxt i18n for in house i18n for web (#5131)
* feat: remove nuxt i18n for in house

* cleanup: remove old nuxt/i18n patch

* prepr

---------

Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
2026-01-15 23:49:38 +00:00

25 lines
779 B
TypeScript

import type { InjectionKey, Ref } from 'vue'
import { inject, provide } from 'vue'
// This doesn't use the architecture outlined in index.ts as it needs some custom checks + use the symbol
export interface I18nContext {
locale: Ref<string>
t: (key: string, values?: Record<string, unknown>) => string
setLocale: (locale: string) => Promise<void> | void
}
export const I18N_INJECTION_KEY: InjectionKey<I18nContext> = Symbol('i18n')
export function injectI18n(): I18nContext {
const context = inject(I18N_INJECTION_KEY)
if (!context) {
throw new Error('Injection `Symbol(i18n)` not found. Ensure the i18n plugin is installed.')
}
return context
}
export function provideI18n(context: I18nContext): I18nContext {
provide(I18N_INJECTION_KEY, context)
return context
}