You've already forked AstralRinth
forked from didirus/AstralRinth
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>
This commit is contained in:
24
packages/ui/src/providers/i18n.ts
Normal file
24
packages/ui/src/providers/i18n.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
}
|
||||
@@ -79,6 +79,7 @@ export function createContext<ContextValue>(
|
||||
}
|
||||
|
||||
export * from './api-client'
|
||||
export * from './i18n'
|
||||
export * from './page-context'
|
||||
export * from './project-page'
|
||||
export * from './server-context'
|
||||
|
||||
Reference in New Issue
Block a user