1- import { useRequestHeaders , useCookie as useNuxtCookie } from '#imports'
1+ import { useNuxtApp , useCookie as useNuxtCookie } from '#imports'
22import { ref } from 'vue'
3- import { parseAcceptLanguage , wrapComposable , runtimeDetectBrowserLanguage } from '../internal'
4- import { localeCodes , normalizedLocales } from '#build/i18n.options.mjs'
3+ import { runtimeDetectBrowserLanguage , wrapComposable } from '../internal'
4+ import { localeCodes } from '#build/i18n.options.mjs'
55import { _useLocaleHead , _useSetI18nParams } from '../routing/head'
66import { getRouteBaseName , localePath , localeRoute , switchLocalePath } from '../routing/routing'
7- import { findBrowserLocale } from '../routing/utils'
87import type { Ref } from 'vue'
98import type { Locale } from 'vue-i18n'
109import type { resolveRoute } from '../routing/routing'
@@ -193,22 +192,13 @@ export function useSwitchLocalePath(): SwitchLocalePathFunction {
193192 * @returns the browser locale, if not detected, return `null`.
194193 */
195194export function useBrowserLocale ( ) : string | null {
196- const headers = useRequestHeaders ( [ 'accept-language' ] )
197- return (
198- findBrowserLocale (
199- normalizedLocales ,
200- import . meta. client ? ( navigator . languages as string [ ] ) : parseAcceptLanguage ( headers [ 'accept-language' ] )
201- ) || null
202- )
195+ return useNuxtApp ( ) . $i18n . getBrowserLocale ( ) || null
203196}
204197
205198/**
206199 * Returns the locale cookie based on `document.cookie` (client-side) or `cookie` header (server-side).
207200 *
208- * @remark
209- * If `detectBrowserLanguage.useCookie` is `false` this will always return an empty string.
210- *
211- * @returns a `Ref<string>` with the detected cookie or an empty string if none is detected.
201+ * @returns a `Ref<string>` with the detected cookie or an empty string if none is detected or if `detectBrowserLanguage.useCookie` is disabled.
212202 */
213203export function useCookieLocale ( ) : Ref < string > {
214204 const locale : Ref < string > = ref ( '' )
@@ -218,17 +208,7 @@ export function useCookieLocale(): Ref<string> {
218208 return locale
219209 }
220210
221- const cookieKey = detect . cookieKey !
222-
223- let code : string | null = null
224- if ( import . meta. client ) {
225- code = useNuxtCookie < string > ( cookieKey ) . value
226- } else if ( import . meta. server ) {
227- const cookie = useRequestHeaders ( [ 'cookie' ] )
228- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
229- code = ( cookie as any ) [ cookieKey ]
230- }
231-
211+ const code : string | null = useNuxtCookie < string > ( detect . cookieKey ! ) . value
232212 if ( code && localeCodes . includes ( code ) ) {
233213 locale . value = code
234214 }
0 commit comments