letlanguages:string[]|undefined// get locale from cookie
constlocaleCookie=request.cookies.get('locale')languages=localeCookie?.value?[localeCookie.value]:[]if(!languages.length){// Negotiator expects plain object so we need to transform headers
constnegotiatorHeaders:Record<string,string>={}request.headers.forEach((value,key)=>(negotiatorHeaders[key]=value))// Use negotiator and intl-localematcher to get best locale
languages=newNegotiator({headers:negotiatorHeaders}).languages()}