raw/angular-dynamic-locale/tmhDynamicLocale.js
function loadLocale(localeUrl, $locale, localeId, $rootScope, $q, localeCache, $timeout) {

    function overrideValues(oldObject, newObject) {
      if (activeLocale !== localeId) {
        return;
      }
      angular.forEach(oldObject, function(value, key) {
        if (!newObject[key]) {
          delete oldObject[key];
        } else if (angular.isArray(newObject[key])) {
          oldObject[key].length = newObject[key].length;
        }
      });
      angular.forEach(newObject, function(value, key) {
        if (angular.isArray(newObject[key]) || angular.isObject(newObject[key])) {
          if (!oldObject[key]) {
            oldObject[key] = angular.isArray(newObject[key]) ? [] : {};
          }
          overrideValues(oldObject[key], newObject[key]);
        } else {
          oldObject[key] = newObject[key];
        }
      });
    }


    if (promiseCache[localeId]) return promiseCache[localeId];

    var cachedLocale,
      deferred = $q.defer();
    if (localeId === activeLocale) {
      deferred.resolve($locale);
    } else if ((cachedLocale = localeCache.get(localeId))) {
      activeLocale = localeId;
      $rootScope.$evalAsync(function() {
        overrideValues($locale, cachedLocale);
        $rootScope.$broadcast('$localeChangeSuccess', localeId, $locale);
        storage.put(storeKey, localeId);
        deferred.resolve($locale);
      });
    } else {
      activeLocale = localeId;
      promiseCache[localeId] = deferred.promise;
      loadScript(localeUrl, function () {
        // Create a new injector with the new locale
        var localInjector = angular.injector(['ngLocale']),
          externalLocale = localInjector.get('$locale');

        overrideValues($locale, externalLocale);
        localeCache.put(localeId, externalLocale);
        delete promiseCache[localeId];

        $rootScope.$apply(function () {
          $rootScope.$broadcast('$localeChangeSuccess', localeId, $locale);
          storage.put(storeKey, localeId);
          deferred.resolve($locale);
        });
      }, function () {
        delete promiseCache[localeId];

        $rootScope.$apply(function () {
          $rootScope.$broadcast('$localeChangeError', localeId);
          deferred.reject(localeId);
        });
      }, $timeout);
    }
    return deferred.promise;
  }
function loadLocale(localeUrl, $locale, localeId, $rootScope, $q, localeCache, $timeout) {

    function overrideValues(oldObject, newObject) {
      if (activeLocale !== localeId) {
        return;
      }
      angular.forEach(oldObject, function(value, key) {
        if (!newObject[key]) {
          delete oldObject[key];
        } else if (angular.isArray(newObject[key])) {
          oldObject[key].length = newObject[key].length;
        }
      });
      angular.forEach(newObject, function(value, key) {
        if (angular.isArray(newObject[key]) || angular.isObject(newObject[key])) {
          if (!oldObject[key]) {
            oldObject[key] = angular.isArray(newObject[key]) ? [] : {};
          }
          overrideValues(oldObject[key], newObject[key]);
        } else {
          oldObject[key] = newObject[key];
        }
      });
    }


    if (promiseCache[localeId]) return promiseCache[localeId];

    var cachedLocale,
      deferred = $q.defer();
    if (localeId === activeLocale) {
      deferred.resolve($locale);
    } else if ((cachedLocale = localeCache.get(localeId))) {
      activeLocale = localeId;
      $rootScope.$evalAsync(function() {
        overrideValues($locale, cachedLocale);
        $rootScope.$broadcast('$localeChangeSuccess', localeId, $locale);
        storage.put(storeKey, localeId);
        deferred.resolve($locale);
      });
    } else {
      activeLocale = localeId;
      promiseCache[localeId] = deferred.promise;
      loadScript(localeUrl, function () {
        // Create a new injector with the new locale
        var localInjector = angular.injector(['ngLocale']),
          externalLocale = localInjector.get('$locale');

        overrideValues($locale, externalLocale);
        localeCache.put(localeId, externalLocale);
        delete promiseCache[localeId];

        $rootScope.$apply(function () {
          $rootScope.$broadcast('$localeChangeSuccess', localeId, $locale);
          storage.put(storeKey, localeId);
          deferred.resolve($locale);
        });
      }, function () {
        delete promiseCache[localeId];

        $rootScope.$apply(function () {
          $rootScope.$broadcast('$localeChangeError', localeId);
          deferred.reject(localeId);
        });
      }, $timeout);
    }
    return deferred.promise;
  }
function loadLocale ( localeUrl , $locale , localeId , $rootScope , $q , localeCache , $timeout ) { function overrideValues ( oldObject , newObject ) { if ( activeLocale !== localeId ) { return ; } angular . forEach ( oldObject , function ( value , key ) { if ( ! newObject [ key ] ) { delete oldObject [ key ] ; } else if ( angular . isArray ( newObject [ key ] ) ) { oldObject [ key ] . length = newObject [ key ] . length ; } } ) ; angular . forEach ( newObject , function ( value , key ) { if ( angular . isArray ( newObject [ key ] ) || angular . isObject ( newObject [ key ] ) ) { if ( ! oldObject [ key ] ) { oldObject [ key ] = angular . isArray ( newObject [ key ] ) ? [ ] : { } ; } overrideValues ( oldObject [ key ] , newObject [ key ] ) ; } else { oldObject [ key ] = newObject [ key ] ; } } ) ; } if ( promiseCache [ localeId ] ) return promiseCache [ localeId ] ; var cachedLocale , deferred = $q . defer ( ) ; if ( localeId === activeLocale ) { deferred . resolve ( $locale ) ; } else if ( ( cachedLocale = localeCache . get ( localeId ) ) ) { activeLocale = localeId ; $rootScope . $evalAsync ( function ( ) { overrideValues ( $locale , cachedLocale ) ; $rootScope . $broadcast ( '$localeChangeSuccess' , localeId , $locale ) ; storage . put ( storeKey , localeId ) ; deferred . resolve ( $locale ) ; } ) ; } else { activeLocale = localeId ; promiseCache [ localeId ] = deferred . promise ; loadScript ( localeUrl , function ( ) { // Create a new injector with the new locale var localInjector = angular . injector ( [ 'ngLocale' ] ) , externalLocale = localInjector . get ( '$locale' ) ; overrideValues ( $locale , externalLocale ) ; localeCache . put ( localeId , externalLocale ) ; delete promiseCache [ localeId ] ; $rootScope . $apply ( function ( ) { $rootScope . $broadcast ( '$localeChangeSuccess' , localeId , $locale ) ; storage . put ( storeKey , localeId ) ; deferred . resolve ( $locale ) ; } ) ; } , function ( ) { delete promiseCache [ localeId ] ; $rootScope . $apply ( function ( ) { $rootScope . $broadcast ( '$localeChangeError' , localeId ) ; deferred . reject ( localeId ) ; } ) ; } , $timeout ) ; } return deferred . promise ; }
Loads a locale and replaces the properties from the current locale with the new locale information

@param localeUrl The path to the new locale
@param $locale The locale at the curent scope
Loads a locale and replaces the properties from the current locale with the new locale information