11import { stringify } from 'devalue'
22import { defineI18nMiddleware } from '@intlify/h3'
33import { defineNitroPlugin , useStorage } from 'nitropack/runtime'
4- import { createI18nContext , tryUseI18nContext , useI18nContext } from './context'
4+ import { initializeI18nContext , tryUseI18nContext , useI18nContext } from './context'
55import { createUserLocaleDetector } from './utils/locale-detector'
66import { pickNested } from './utils/messages-utils'
7- import { createLocaleConfigs , getDefaultLocaleForDomain , isSupportedLocale } from '../shared/locales'
7+ import { isSupportedLocale } from '../shared/locales'
88import { setupVueI18nOptions } from '../shared/vue-i18n'
99import { joinURL } from 'ufo'
1010// @ts -expect-error virtual file
@@ -19,8 +19,6 @@ import { useDetectors } from '../shared/detection'
1919import { domainFromLocale } from '../shared/domain'
2020import { isExistingNuxtRoute , matchLocalized } from '../shared/matching'
2121
22- const getHost = ( event : H3Event ) => getRequestURL ( event , { xForwardedHost : true } ) . host
23-
2422function * detect (
2523 detectors : ReturnType < typeof useDetectors > ,
2624 detection : ReturnType < typeof useI18nDetection > ,
@@ -145,26 +143,14 @@ export default defineNitroPlugin(async (nitro) => {
145143
146144 const baseUrlGetter = createBaseUrlGetter ( )
147145
148- async function initialize ( event : H3Event ) {
149- const options = await setupVueI18nOptions ( getDefaultLocaleForDomain ( getHost ( event ) ) || _defaultLocale )
150- const localeConfigs = createLocaleConfigs ( options . fallbackLocale )
151- const ctx = createI18nContext ( )
152-
153- ctx . vueI18nOptions = options
154- ctx . localeConfigs = localeConfigs
155-
156- event . context . nuxtI18n = ctx
157- return ctx
158- }
159-
160146 nitro . hooks . hook ( 'request' , async ( event : H3Event ) => {
161- await initialize ( event )
147+ await initializeI18nContext ( event )
162148 } )
163149
164150 nitro . hooks . hook ( 'render:before' , async ( { event } ) => {
165151 if ( ! __I18N_SERVER_REDIRECT__ ) { return }
166152
167- const ctx = import . meta. prerender && ! event . context . nuxtI18n ? await initialize ( event ) : useI18nContext ( event )
153+ const ctx = import . meta. prerender && ! event . context . nuxtI18n ? await initializeI18nContext ( event ) : useI18nContext ( event )
168154 const url = getRequestURL ( event )
169155 const detector = useDetectors ( event , detection )
170156 const localeSegment = detector . route ( event . path )
0 commit comments