<commit_before>(function(angular){

  "use strict"

  var app = angular.module("ov.i18n", ["ngCookies", "ngRoute"]);

  app.factory("i18nService", I18nService);
  app.filter("translate", TranslateFilter);
  I18nService.$inject = ["$http", "$route", "$cookies"];
  TranslateFilter.$inject = ["i18nService"];
  
  /**
   * Defines an internationalization service to manage
   * string translations.
   * TODO Make it a provider to configure the list of supported languages
   */
  function I18nService($http, $route, $cookies){
    var currentLanguage = $cookies.language || navigator.language || navigator.browserLanguage;
    var translations = {};
    var supportedLanguages = [];

    var init = function(){
      supportedLanguages = [
        {
          "value" : "en",
          "label" : "ENGLISH"
        },
        {
          "value" : "fr",
          "label" : "FRENCH"
        }
      ];

      // Verify if current language is supported, otherwise
      // set language to the first one in the list of supported languages
      if(!isLanguageSupported(currentLanguage)){
        var language = currentLanguage.split("-")[0];
        if(isLanguageSupported(language))
          setLanguage(language);
        else
          setLanguage(supportedLanguages[0].value);
      }
      else
        setActiveLanguage();
    };

    /**
     * Adds a new dictionary, to the translation table, for the current
     * language.
     * A dictionary is referenced by its name and contains a JSON 
     * representation of all its translations.
     * If dictionary does not exist yet, get it from the server. 
     *
     * @param String name The name of the dictionary to retrieve from 
     * server
     * @param Boolean admin true to retrieve a dictionary for the back 
     * office part (which requires authentication), false to get a
     * dictionary without access restriction
     */
    var addDictionary = function(name, admin){

      // Dictionary for the currentLanguage
      if(name && (!translations[name] || translations[name][currentLanguage] === undefined)){
        admin || (admin = false);
        
        var path = admin ? "/admin/" : "/";
        path += "getDictionary/" + name + "/" + currentLanguage;
        
        // Get dictionary
        return $http.get(path).success(function(translation){
          translations[name] || (translations[name] = {});
          translations[name][currentLanguage] = translation;
        }).error(function(){
           translations[name] || (translations[name] = {});
           translations[name][currentLanguage] = null;
        });
      }
    };
    
    /**
     * Removes a dictionary.
     * @param String name The dictionary name
     */
    var removeDictionary = function(name){
      translations[name] && (delete translations[name]);
    };
    
    /**
     * Gets a dictionary with all its languages or just for the specific 
     * language.
     * @param String name The dictionary name
     * @param String language An optional language to retrieve
     * @return Object The translations contained in the dictionary
     */
    var getDictionary = function(name, language){
      if(language && translations[name])
        return translations[name][language];
        
      return translations[name];
    };
    
    /**
     * Gets current language.
     * @return String The current language country code (e.g en-US)
     */
    var getLanguage = function(){
      return currentLanguage;
    };
    
    /**
     * Gets supported languages.
     * @return Array The list of supported languages
     */
    var getLanguages = function(){
      return supportedLanguages;
    };

    /**
     * Sets current language.
     * Changing the current language will reload the current route.
     *
     * @param String language The current language country 
     * code (e.g en-CA)
     */
    var setLanguage = function(language){
      if(isLanguageSupported(language)){
        currentLanguage = language;
        $cookies.language = currentLanguage;
        setActiveLanguage(currentLanguage);
        $route.reload();
      }
    };<commit_msg>Correct bug on back end translation<commit_after>(function(angular){

  "use strict"

  var app = angular.module("ov.i18n", ["ngCookies", "ngRoute"]);

  app.factory("i18nService", I18nService);
  app.filter("translate", TranslateFilter);
  I18nService.$inject = ["$http", "$route", "$cookies"];
  TranslateFilter.$inject = ["i18nService"];
  
  /**
   * Defines an internationalization service to manage
   * string translations.
   * TODO Make it a provider to configure the list of supported languages
   */
  function I18nService($http, $route, $cookies){
    var currentLanguage = $cookies.get("language") || navigator.language || navigator.browserLanguage;
    var translations = {};
    var supportedLanguages = [];

    var init = function(){
      supportedLanguages = [
        {
          "value" : "en",
          "label" : "ENGLISH"
        },
        {
          "value" : "fr",
          "label" : "FRENCH"
        }
      ];

      // Verify if current language is supported, otherwise
      // set language to the first one in the list of supported languages
      if(!isLanguageSupported(currentLanguage)){
        var language = currentLanguage.split("-")[0];
        if(isLanguageSupported(language))
          setLanguage(language);
        else
          setLanguage(supportedLanguages[0].value);
      }
      else
        setActiveLanguage();
    };

    /**
     * Adds a new dictionary, to the translation table, for the current
     * language.
     * A dictionary is referenced by its name and contains a JSON 
     * representation of all its translations.
     * If dictionary does not exist yet, get it from the server. 
     *
     * @param String name The name of the dictionary to retrieve from 
     * server
     * @param Boolean admin true to retrieve a dictionary for the back 
     * office part (which requires authentication), false to get a
     * dictionary without access restriction
     */
    var addDictionary = function(name, admin){

      // Dictionary for the currentLanguage
      if(name && (!translations[name] || translations[name][currentLanguage] === undefined)){
        admin || (admin = false);
        
        var path = admin ? "/admin/" : "/";
        path += "getDictionary/" + name + "/" + currentLanguage;
        
        // Get dictionary
        return $http.get(path).success(function(translation){
          translations[name] || (translations[name] = {});
          translations[name][currentLanguage] = translation;
        }).error(function(){
           translations[name] || (translations[name] = {});
           translations[name][currentLanguage] = null;
        });
      }
    };
    
    /**
     * Removes a dictionary.
     * @param String name The dictionary name
     */
    var removeDictionary = function(name){
      translations[name] && (delete translations[name]);
    };
    
    /**
     * Gets a dictionary with all its languages or just for the specific 
     * language.
     * @param String name The dictionary name
     * @param String language An optional language to retrieve
     * @return Object The translations contained in the dictionary
     */
    var getDictionary = function(name, language){
      if(language && translations[name])
        return translations[name][language];
        
      return translations[name];
    };
    
    /**
     * Gets current language.
     * @return String The current language country code (e.g en-US)
     */
    var getLanguage = function(){
      return currentLanguage;
    };
    
    /**
     * Gets supported languages.
     * @return Array The list of supported languages
     */
    var getLanguages = function(){
      return supportedLanguages;
    };

    /**
     * Sets current language.
     * Changing the current language will reload the current route.
     *
     * @param String language The current language country 
     * code (e.g en-CA)
     */
    var setLanguage = function(language){
      if(isLanguageSupported(language)){
        currentLanguage = language;
        $cookies.put("language", currentLanguage);
        setActiveLanguage(currentLanguage);
        $route.reload();
      }
    };
{'fraction_non_alphanumeric': 0.11032157051668072, 'fraction_numerical': 0.003372275081295917, 'mean_word_length': 2.4215080346106306, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4651815', 'n_tokens_mistral': 2162, 'n_tokens_neox': 2096, 'n_words': 659}