📝Inject Service

There are situations where you will need to translate your texts within the service.

src/core/locales/en.json
{
  "hello": "Hello World"
}
import { Injectable } from '@nestjs/common';
import { LocaleService } from '@/core/i18n/i18n.service';

@Injectable()
export class AppService {
  constructor(private readonly localeService: LocaleService) {}
  
  getHello(): string {
    return this.localeService.translate('hello');
  } // output: Hello World
}

Simply you can inject the service from locale and translate your texts.

Last updated