import type { CallHandler , ExecutionContext , NestInterceptor , } from '@nestjs/common' ; import { Injectable , UseInterceptors } from '@nestjs/common' ; import type { Observable } from 'rxjs' ; import { LanguageCode } from '../constants' ; import { ContextProvider } from '../providers' ; @ Injectable ( ) export class LanguageInterceptor implements NestInterceptor { intercept ( context , next ) { const request = context . switchToHttp ( ) . getRequest ( ) ; const language = request . headers [ 'x-language' ] ?. toUpperCase ( ) ; if ( LanguageCode [ language ] ) { ContextProvider . setLanguage ( language ) ; } return next . handle ( ) ; } } export function UseLanguageInterceptor ( ) { return UseInterceptors ( LanguageInterceptor ) ; }