import { I18nResolver } from '../index' ; import { Injectable , ExecutionContext } from '@nestjs/common' ; import { I18nResolverOptions } from '../decorators/i18n-resolver-options.decorator' ; @ Injectable ( ) export class HeaderResolver implements I18nResolver { constructor ( @ I18nResolverOptions ( ) private keys = [ ] ) { } resolve ( context ) { let req ; switch ( context . getType ( ) as string ) { case 'http' : req = context . switchToHttp ( ) . getRequest ( ) ; break ; case 'graphql' : [ , , { req } ] = context . getArgs ( ) ; break ; } let lang ; if ( req ) { for ( const key of this . keys ) { if ( key === 'accept-language' ) { console . warn ( 'HeaderResolver does not support RFC4647 Accept-Language header. Please use AcceptLanguageResolver instead.' ) ; } if ( req . headers !== undefined && req . headers [ key ] !== undefined ) { lang = req . headers [ key ] ; break ; } } } return lang ; } }