All files / lib/services i18n-request-scope.service.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 4/4
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 245x 5x 5x     10x   42x 42x       14x       14x       2x   5x  
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: I18nService,
  ) {}
 
  public translate(key: string, options?: translateOptions) {
    options = {
      lang: this.req.i18nLang,
      ...options,
    };
    return this.i18nService.translate(key, options);
  }
 
  public t(key: string, options?: translateOptions) {
    return this.translate(key, options);
  }
}