<commit_before>import * as i18next from 'i18next';
import { TranslationFunction, InitOptions } from 'i18next';
import { injectPropertyToAllComponents } from '../components-registry';
import { logger } from '../logger-lib/logger';

const log = logger.get('poa-i18n');

export interface PoaI18nOpts extends InitOptions {
  // TODO: display loading placeholder when i18next options has async loading
  // tslint:disable-next-line:no-any
  loadingPlaceholder?: React.ReactElement<any>;
}
export interface Translator extends TranslationFunction {}

export function bootstrapLocalization(config: InitOptions) {
  return new Promise((resolve, reject) => {
    // tslint:disable-next-line:no-any
    i18next.init(config, (error: any, t: TranslationFunction) => {
      if (error) {
        return reject(error);
      }

      injectPropertyToAllComponents(component => {
        component.prototype.t = translatorFuncCreator(component.prototype.tNamespaces || [], t);
      });

      // tslint:disable-next-line:no-any
      log.debug('initialized with options', (i18next as any).default.options);
      return resolve(t);
    });
  });
}

export const i18n = i18next;

// tslint:disable-next-line:no-any
export const translatorFuncCreator = (dicts: string[], t: any) => (value: string, opts?: {}) => {
  return t(value, { ns: [...dicts], ...opts });
};<commit_msg>fix(logger): Remove i18n debug logs<commit_after>import * as i18next from 'i18next';
import { TranslationFunction, InitOptions } from 'i18next';
import { injectPropertyToAllComponents } from '../components-registry';
import { logger } from '../logger-lib/logger';

const log = logger.get('poa-i18n');

export interface PoaI18nOpts extends InitOptions {
  // TODO: display loading placeholder when i18next options has async loading
  // tslint:disable-next-line:no-any
  loadingPlaceholder?: React.ReactElement<any>;
}
export interface Translator extends TranslationFunction {}

export function bootstrapLocalization(config: InitOptions) {
  return new Promise((resolve, reject) => {
    // tslint:disable-next-line:no-any
    i18next.init(config, (error: any, t: TranslationFunction) => {
      if (error) {
        return reject(error);
      }

      injectPropertyToAllComponents(component => {
        component.prototype.t = translatorFuncCreator(component.prototype.tNamespaces || [], t);
      });

      return resolve(t);
    });
  });
}

export const i18n = i18next;

// tslint:disable-next-line:no-any
export const translatorFuncCreator = (dicts: string[], t: any) => (value: string, opts?: {}) => {
  return t(value, { ns: [...dicts], ...opts });
};
{'fraction_non_alphanumeric': 0.14083969465648855, 'fraction_numerical': 0.015267175572519083, 'mean_word_length': 4.030710172744722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6857221', 'n_tokens_mistral': 803, 'n_tokens_neox': 773, 'n_words': 187}