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

100% Statements 11/11
100% Branches 0/0
100% Functions 3/3
100% Lines 9/9

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     5x   112x 112x       42x       42x       16x      
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);
  }
}