All files / src/components/i18next/providers i18next.ts

100% Statements 12/12
66.67% Branches 2/3
100% Functions 2/2
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 24 25 26 27 28 29 30 31 32 33 341x 1x 1x   1x             1x 1x     1x 1x 1x                         1x      
import i18next, {TFunction} from 'i18next';
import Backend from 'i18next-fs-backend';
import {join} from 'path';
 
import {config, Provider} from '@loopback/core';
 
import {I18NextOptions} from '../types';
 
/**
 * A provider class that creates I18NextTranslate instances
 */
export class I18NextTranslatorProvider implements Provider<TFunction> {
  constructor(@config() private options: I18NextOptions = {}) {}
 
  async value() {
    const localesPath = join(process.cwd(), 'src/components/i18next/locales/{{lng}}/{{ns}}.json');
    Eif (!i18next.isInitialized) {
      await i18next.use(Backend).init({
        debug: false,
        initImmediate: false,
        fallbackLng: 'en',
        preload: ['en', 'es', 'ja', 'vi', 'zh'],
        lng: 'en',
        ns: 'notification',
        defaultNS: 'notification',
        backend: {
          loadPath: localesPath,
        },
      });
    }
    return i18next.t.bind(i18next);
  }
}