<commit_before>
var Localize = (function() {
    var scripts = document.getElementsByTagName('script');
    var localizeScript = scripts[scripts.length - 1];

    var keyword = localizeScript.getAttribute('keyword') || 'translate',
        path = localizeScript.getAttribute('path') || '/translations/',
        defaultLang = localizeScript.getAttribute('default-lang') || 'en',
        translations = {};

  /**
   * Translates the page using the specified language
   * @param {String} lang
   */
  function translate(lang) {
    var translationLang = lang || navigator.language || navigator.userLanguage || (navigator.languages ? navigator.languages[0] : defaultLang),
        elems = Array.prototype.slice.call(document.querySelectorAll('[' + keyword + ']'));

    getTranslations(translationLang, function(translations) {
      elems.forEach(function(elem) {
        var key = elem.getAttribute(keyword);
        if (translations[key]) {
          elem.innerHTML = translations[key];
        }
      });
    });
  };

  /**
   * Retrieve translations object from a JSON file
   * @param {String} lang
   * @param {function(Object)} cb
   */
   function getTranslations(lang, cb) {

    if (translations[lang]){
      cb(translations[lang]);
      return;
    }

    var xhttp = new XMLHttpRequest();
    xhttp.open("GET", path + lang + ".json", true);
    xhttp.send();
    var retry = true;
    xhttp.onreadystatechange = function() {
      if (xhttp.readyState == 4) {
        if (xhttp.status == 404 && retry) {
          if (lang.length > 2) {
            lang = lang.substring(0,2);
            xhttp.open("GET", path + lang.substring(0,2) + ".json", true);
            xhttp.send();
            retry = false;
          }
        }
        else if (xhttp.status == 200) {
          translations[lang] = JSON.parse(xhttp.responseText);
          cb(translations[lang]);
          return;
        }
      }
    };
  }

  translate(defaultLang);
  return {
    translate: translate
  }
})();<commit_msg>expose current language in Localize object<commit_after>
var Localize = (function() {
    var scripts = document.getElementsByTagName('script');
    var localizeScript = scripts[scripts.length - 1];

    var keyword = localizeScript.getAttribute('keyword') || 'translate',
        path = localizeScript.getAttribute('path') || '/translations/',
        defaultLang = localizeScript.getAttribute('default-lang') || 'en',
        translations = {};

  /**
   * Translates the page using the specified language
   * @param {String} lang
   */
  function translate(lang) {
    var translationLang = lang || navigator.language || navigator.userLanguage || (navigator.languages ? navigator.languages[0] : defaultLang),
        elems = Array.prototype.slice.call(document.querySelectorAll('[' + keyword + ']'));

    if (Localize) {
      Localize.currentLang = lang;
    }
    
    getTranslations(translationLang, function(translations) {
      elems.forEach(function(elem) {
        var key = elem.getAttribute(keyword);
        if (translations[key]) {
          elem.innerHTML = translations[key];
        }
      });
    });
  };

  /**
   * Retrieve translations object from a JSON file
   * @param {String} lang
   * @param {function(Object)} cb
   */
   function getTranslations(lang, cb) {

    if (translations[lang]){
      cb(translations[lang]);
      return;
    }

    var xhttp = new XMLHttpRequest();
    xhttp.open("GET", path + lang + ".json", true);
    xhttp.send();
    var retry = true;
    xhttp.onreadystatechange = function() {
      if (xhttp.readyState == 4) {
        if (xhttp.status == 404 && retry) {
          if (lang.length > 2) {
            lang = lang.substring(0,2);
            xhttp.open("GET", path + lang.substring(0,2) + ".json", true);
            xhttp.send();
            retry = false;
          }
        }
        else if (xhttp.status == 200) {
          translations[lang] = JSON.parse(xhttp.responseText);
          cb(translations[lang]);
          return;
        }
      }
    };
  }

  translate(defaultLang);
  return {
    translate: translate,
    currentLang: defaultLang
  };
})();
{'fraction_non_alphanumeric': 0.14223722275795564, 'fraction_numerical': 0.006750241080038573, 'mean_word_length': 2.507185122569738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6455519', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1208, 'n_words': 255}