<commit_before>import i18next from 'i18next';
import i18nextXhr from 'i18next-xhr-backend';
import i18nextLangDetector from 'i18next-browser-languagedetector';
import config from '../appConfig.js';

class I18nTranslator {
  constructor() {
    this.translator = null;
  }

  initiateTranslator(resolve) {
    return new Promise(() => {
      i18next
        .use(i18nextXhr)
        .use(i18nextLangDetector)
        .init({
          fallbackLng: 'en',
          backend: {
            loadPath: `${config.translationFolder}/{{lng}}/translation.json`,
          },
          detection: {
            order: ['cookie'],
            caches: [],
            lookupCookie: 'lang',
          },
        }, (err, t) => {
          if (err) {
            console.log("something went wrong");
            console.log(err);
          } else {
            this.translator = t;
            resolve();
          }
        });
    });
  }

  translate(key) {
    if (!this.translator) {
      throw new Error('Translator not initialized');
    }
    return this.translator(key);
  }
}

const translatorInstance = new I18nTranslator();

export default translatorInstance;
<commit_msg>Adding supported languages.<commit_after>import i18next from 'i18next';
import i18nextXhr from 'i18next-xhr-backend';
import i18nextLangDetector from 'i18next-browser-languagedetector';
import config from '../appConfig.js';
import Cookie from 'js-cookie';

const supportedlanguages = [
  'en',
  'fr'
];

class I18nTranslator {
  constructor() {
    this.translator = null;
  }

  initiateTranslator(resolve) {
    return new Promise(() => {
      let langToDisplay;
      if(!Cookie.get('lang'))
        langToDisplay = 'en';
      langToDisplay = (supportedlanguages.filter(lang => lang === Cookie.get('lang')).length > 0) ? Cookie.get('lang') : 'en';
      i18next
        .use(i18nextXhr)
        .use(i18nextLangDetector)
        .init({
          fallbackLng: 'en',
          backend: {
            loadPath: `${config.translationFolder}/${langToDisplay}/translation.json`,
          },
          detection: {
            order: ['cookie'],
            caches: [],
            lookupCookie: 'lang',
          },
        }, (err, t) => {
          if (err) {
            console.log("something went wrong");
            console.log(err);
          } else {
            this.translator = t;
            resolve();
          }
        });
    });
  }

  translate(key) {
    if (!this.translator) {
      throw new Error('Translator not initialized');
    }
    return this.translator(key);
  }
}

const translatorInstance = new I18nTranslator();

export default translatorInstance;

{'fraction_non_alphanumeric': 0.13473842679713963, 'fraction_numerical': 0.016936394429808054, 'mean_word_length': 2.1381345926800472, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1831819', 'n_tokens_mistral': 827, 'n_tokens_neox': 793, 'n_words': 160}