<commit_before>
// require dependencies
const riot     = require ('riot');
const i18n     = require ('i18next');
const cache    = require ('i18next-localstorage-cache');
const backend  = require ('i18next-xhr-backend');
const sprintf  = require ('i18next-sprintf-postprocessor');
const detector = require ('i18next-browser-languagedetector');

// load riot store
const riotStore = require ('riot/public/js/store');

/**
 * create locale store
 */
class localeStore {
  /**
   * construct riot store
   */
  constructor () {
    // set observable
    riot.observable (this);

    // set i18n
    this.i18n = i18n;

    // bind i18n methods
    this.t = this.i18n.t.bind (this.i18n);

    // bind methods
    this.lang  = this.lang.bind (this);
    this.build = this.build.bind (this);

    // build store
    this.build ();
  }

  /**
   * build locale store
   */
  build () {
    // load i18n
    let load = riotStore.get ('i18n');

    // use functions
    this.i18n
      .use (detector)
      .use (backend)
      .use (cache)
      .use (sprintf);

    // init
    this.i18n.init (load, () => this.trigger ('upate'));

    // on load
    this.i18n.on ('loaded', () => this.trigger ('update'));

    // set translate function
    this.t = this.i18n.t.bind (this.i18n);
  }

  /**
   * sets language
   *
   * @param {String} lang
   */
  lang (lang) {
    // check language
    if (!lang) {
      // load language
      if (!this.i18n.language) return false;

      // load only one
      if (this.i18n.language.indexOf (' ') > -1) {
        return this.i18n.language.split (' ')[this.i18n.language.split (' ').length - 1];
      }

      // return language
      return this.i18n.language;<commit_msg>complete cache logic for i18n bundle<commit_after>
// require dependencies
const riot     = require ('riot');
const i18n     = require ('i18next');
const cache    = require ('i18next-localstorage-cache');
const backend  = require ('i18next-xhr-backend');
const sprintf  = require ('i18next-sprintf-postprocessor');
const detector = require ('i18next-browser-languagedetector');

// load riot store
const riotStore = require ('riot/public/js/store');

/**
 * create locale store
 */
class localeStore {
  /**
   * construct riot store
   */
  constructor () {
    // set observable
    riot.observable (this);

    // set i18n
    this.i18n = i18n;

    // bind i18n methods
    this.t = this.i18n.t.bind (this.i18n);

    // bind methods
    this.lang  = this.lang.bind (this);
    this.build = this.build.bind (this);

    // build store
    this.build ();
  }

  /**
   * build locale store
   */
  build () {
    // load i18n
    let load = riotStore.get ('i18n');

    // use functions
    this.i18n
      .use (detector)
      .use (cache)
      .use (backend)
      .use (sprintf);

    // init
    this.i18n.init (load, () => this.trigger ('upate'));

    // on load
    this.i18n.on ('loaded', () => this.trigger ('update'));

    // set translate function
    this.t = this.i18n.t.bind (this.i18n);
  }

  /**
   * sets language
   *
   * @param {String} lang
   */
  lang (lang) {
    // check language
    if (!lang) {
      // load language
      if (!this.i18n.language) return false;

      // load only one
      if (this.i18n.language.indexOf (' ') > -1) {
        return this.i18n.language.split (' ')[this.i18n.language.split (' ').length - 1];
      }

      // return language
      return this.i18n.language;
{'fraction_non_alphanumeric': 0.1572052401746725, 'fraction_numerical': 0.029694323144104803, 'mean_word_length': 2.1873840445269015, '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': '6524101', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1136, 'n_words': 280}