User Locale in middleware
Unanswered
Kuchi posted this in #help-forum
KuchiOP
import { NextResponse } from "next/server";
import { match } from '@formatjs/intl-localematcher'
import Negotiator from 'negotiator'
let headers = { 'accept-language': 'en-US,en;q=0.5' }
let languages = new Negotiator({ headers }).languages()
let locales = ['en-US', 'fr-CA', 'zh-Hans', 'hi-IN', ]
let defaultLocale = 'en-US'
let userLocale = match(languages, locales, defaultLocale) // -> 'en-US'This is from the docs of internationalization from next.js https://nextjs.org/docs/app/building-your-application/routing/internationalization
If I'm trying to get the user locale using header, I'll need to access the headers of the user - but in their example they statically set the header value, how do I access the headers from the user?