<commit_before>function TranslationManager(inputManager, storageManager) {
  this.storage      = storageManager;
  this.inputManager = inputManager;

  this.number_of_languages = 0;
}

TranslationManager.prototype.loadAvailableQuestionnaires = function(){
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = undefined;
      var json_parsed               = JSON.parse(request.responseText);
			var available_questionnaires  = json_parsed.questionnaires;
      var number_of_questionnaires  = available_questionnaires.length;
      // initialize the available languages
      for(var i=0; i < number_of_questionnaires; i++){
        self.initializeQuestionnaires(available_questionnaires[i]);
      }
      self.inputManager.emit("allQuestionnairesInitialized");
		}
	};
  request.overrideMimeType('text/json');
  request.open("GET", "questionnaire.txt", true);
  request.send();
};

TranslationManager.prototype.initializeQuestionnaires = function(questionnaire){
  this.loadAvailableLanguages(questionnaire);
  this.inputManager.emit("questionnaireInitialized", questionnaire);
};

TranslationManager.prototype.getQuestionnaireKey = function(questionnaire){
    return "questionnaire-" + questionnaire;
}

TranslationManager.prototype.loadAvailableUILanguages = function(){
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = undefined;
      var json_parsed           = JSON.parse(request.responseText);
			var available_languages   = json_parsed.languages;
      var numberofquestions     = json_parsed.numberofquestions;
      var number_of_languages   = available_languages.length;
      self.addAvailableLanguageCounter(number_of_languages);
      // hand over question package related information to the ApplicationManager
      self.inputManager.emit("setQuestionpackInfos");
      // initialize the available languages
      for(var i=0; i < number_of_languages; i++){
        self.initializeLanguage("ui", available_languages[i]);
      }
		}
	};
  request.overrideMimeType('text/json');
  request.open("GET", "locales" + "/" + "ui" + "/" + "languages.txt", true);
  request.send();
};

TranslationManager.prototype.loadAvailableLanguages = function(questionnaire){
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = undefined;
      var json_parsed           = JSON.parse(request.responseText);
			var available_languages   = json_parsed.languages;
      var numberofquestions     = json_parsed.numberofquestions;
      var number_of_languages   = available_languages.length;
      var default_title         = json_parsed.defaulttitle;
      self.addAvailableLanguageCounter(number_of_languages);
      // hand over question package related information to the ApplicationManager
      self.inputManager.emit("setQuestionpackInfos", {
        "available_languages": available_languages,
        "number_of_questions": numberofquestions,
        "questionnaire": questionnaire,
      });
      // initialize the available languages
      for(var i=0; i < number_of_languages; i++){
        self.initializeLanguage(questionnaire, available_languages[i]);
      }
      // save the default title
      self.setTranslation(undefined, "default", self.getQuestionnaireKey(questionnaire), "(No translation) " + default_title);
		}
	};
  request.overrideMimeType('text/json');
  request.open("GET", "locales" + "/" + questionnaire + "/" + "languages.txt", true);
  request.send();
};

TranslationManager.prototype.addAvailableLanguageCounter = function(value){
  this.number_of_languages = this.number_of_languages + value;
};

TranslationManager.prototype.decreaseAvailableLanguageCounter = function(){
  this.number_of_languages = this.number_of_languages - 1;
  if(this.number_of_languages === 0){
    this.inputManager.emit("allLanguageInitialized");
  }
};

TranslationManager.prototype.initializeLanguage = function(questionnaire, language){
  // if the language is already initialized, abort
  if(this.isLanguageSupported(language)){
    this.inputManager.emit("languageInitialized", language);
    this.decreaseAvailableLanguageCounter();
    return;
  }
  // load the language
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
      devlog("Ready new language file: " + request.responseURL);
			request.onreadystatechange = undefined;
      // check whether data were loaded
      if(!request.responseText || request.responseText === ""){
        throw "Exception: could not read the content of '" + language + ".json'.";
      }
      // check whether the language matches the requested one
			var language_obj   = JSON.parse(request.responseText);
      if(language !== language_obj.ln){
        throw "IllegalStateException: when reading '" + language + ".json', the content is marked as '" + language_obj.ln + "'.";
      }
      var questionnaire_key = self.getQuestionnaireKey(questionnaire);<commit_msg>Fixed printout fault in exception message<commit_after>function TranslationManager(inputManager, storageManager) {
  this.storage      = storageManager;
  this.inputManager = inputManager;

  this.number_of_languages = 0;
}

TranslationManager.prototype.loadAvailableQuestionnaires = function(){
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = undefined;
      var json_parsed               = JSON.parse(request.responseText);
			var available_questionnaires  = json_parsed.questionnaires;
      var number_of_questionnaires  = available_questionnaires.length;
      // initialize the available languages
      for(var i=0; i < number_of_questionnaires; i++){
        self.initializeQuestionnaires(available_questionnaires[i]);
      }
      self.inputManager.emit("allQuestionnairesInitialized");
		}
	};
  request.overrideMimeType('text/json');
  request.open("GET", "questionnaire.txt", true);
  request.send();
};

TranslationManager.prototype.initializeQuestionnaires = function(questionnaire){
  this.loadAvailableLanguages(questionnaire);
  this.inputManager.emit("questionnaireInitialized", questionnaire);
};

TranslationManager.prototype.getQuestionnaireKey = function(questionnaire){
    return "questionnaire-" + questionnaire;
}

TranslationManager.prototype.loadAvailableUILanguages = function(){
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = undefined;
      var json_parsed           = JSON.parse(request.responseText);
			var available_languages   = json_parsed.languages;
      var numberofquestions     = json_parsed.numberofquestions;
      var number_of_languages   = available_languages.length;
      self.addAvailableLanguageCounter(number_of_languages);
      // hand over question package related information to the ApplicationManager
      self.inputManager.emit("setQuestionpackInfos");
      // initialize the available languages
      for(var i=0; i < number_of_languages; i++){
        self.initializeLanguage("ui", available_languages[i]);
      }
		}
	};
  request.overrideMimeType('text/json');
  request.open("GET", "locales" + "/" + "ui" + "/" + "languages.txt", true);
  request.send();
};

TranslationManager.prototype.loadAvailableLanguages = function(questionnaire){
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = undefined;
      var json_parsed           = JSON.parse(request.responseText);
			var available_languages   = json_parsed.languages;
      var numberofquestions     = json_parsed.numberofquestions;
      var number_of_languages   = available_languages.length;
      var default_title         = json_parsed.defaulttitle;
      self.addAvailableLanguageCounter(number_of_languages);
      // hand over question package related information to the ApplicationManager
      self.inputManager.emit("setQuestionpackInfos", {
        "available_languages": available_languages,
        "number_of_questions": numberofquestions,
        "questionnaire": questionnaire,
      });
      // initialize the available languages
      for(var i=0; i < number_of_languages; i++){
        self.initializeLanguage(questionnaire, available_languages[i]);
      }
      // save the default title
      self.setTranslation(undefined, "default", self.getQuestionnaireKey(questionnaire), "(No translation) " + default_title);
		}
	};
  request.overrideMimeType('text/json');
  request.open("GET", "locales" + "/" + questionnaire + "/" + "languages.txt", true);
  request.send();
};

TranslationManager.prototype.addAvailableLanguageCounter = function(value){
  this.number_of_languages = this.number_of_languages + value;
};

TranslationManager.prototype.decreaseAvailableLanguageCounter = function(){
  this.number_of_languages = this.number_of_languages - 1;
  if(this.number_of_languages === 0){
    this.inputManager.emit("allLanguageInitialized");
  }
};

TranslationManager.prototype.initializeLanguage = function(questionnaire, language){
  // if the language is already initialized, abort
  if(this.isLanguageSupported(language)){
    this.inputManager.emit("languageInitialized", language);
    this.decreaseAvailableLanguageCounter();
    return;
  }
  // load the language
  var self = this;
  var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
      devlog("Ready new language file: " + request.responseURL);
			request.onreadystatechange = undefined;
      // check whether data were loaded
      if(!request.responseText || request.responseText === ""){
        throw "Exception: could not read the content of '" + language + ".json'.";
      }
      // check whether the language matches the requested one
			var language_obj   = JSON.parse(request.responseText);
      if(language !== language_obj.ln){
        throw "IllegalStateException: when reading '" + language + ".ln', the content is marked as '" + language_obj.ln + "'.";
      }
      var questionnaire_key = self.getQuestionnaireKey(questionnaire);
{'fraction_non_alphanumeric': 0.10984230560087004, 'fraction_numerical': 0.0018125793003443901, 'mean_word_length': 4.229857819905213, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 3, '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': '7625466', 'n_tokens_mistral': 3071, 'n_tokens_neox': 2988, 'n_words': 604}