import { Inject , Injectable , Scope } from '@nestjs/common' ; import { REQUEST } from '@nestjs/core' ; import { I18nService , translateOptions } from './i18n.service' ; @ Injectable ( { scope : Scope . REQUEST } ) export class I18nRequestScopeService { constructor ( @ Inject ( REQUEST ) private readonly req , private readonly i18nService ) { } public translate ( key , options ? ) { const lang = ( ! this . req . i18nLang && this . req . context ) ? this . req . context . i18nLang : this . req . i18nLang ; options = { lang , ... options , } ; return this . i18nService . translate ( key , options ) ; } public t ( key , options ? ) { return this . translate ( key , options ) ; } }