<commit_before>
/**
 * Module dependencies.
 */

var fs = require('fs');
var Q = require('q');
var parser = require('./parser');
var syntax = require('./syntax');
var _ = require('underscore');
var merger = require('./merger');
var readline = require('readline');
var file = require('./file');
var log = require('./_log');
var Hashids = require('hashids');
var hashids = new Hashids(program.LOCALIZATION_ID_HASH_SECRET, program.LOCALIZATION_ID_CHARACTER_LENGTH);

/**
 * Add terminal colors
 */

require('terminal-colors');

/**
 * Update
 *
 * @constructor
 */

function Update() {
  this.isWaitingUserInput = false;
  this.deletedKeys = [];
  this.addedKeys = [];
  this.migratedKeys = [];
  this.rl = null;
}

/**
 * Update keys
 *
 * @return {void}
 * @api public
 */

Update.prototype.run = function() {
  var _this = this;

  this.getNewLocalizations()
    .then(function(newLocalizations) {
      return _this._mergeWithOldLocalizations(newLocalizations);
    })
    .then(function(mergedLocalizations) {
      return file.writeLocalizations(mergedLocalizations)
    })
    .fail(function(error) {
      if(commands.stack && error) {
        console.log(error.stack);
      }

      log.error('Localizations update failed');
    });
};

/**
 * Strip inner functions calls. All function calls that is not from l10ns
 * needs to be removed. Because they can cause updating error
 * when they are defined inside variables like below
 *
 *    Example:
 *
 *      gt('SOME_TRANSLATION_KEY', {
 *        prop1 : test() // Becomes ''
 *      });<commit_msg>Fixes #102 - Different passed in variables doesnt show error message<commit_after>
/**
 * Module dependencies.
 */

var fs = require('fs');
var Q = require('q');
var parser = require('./parser');
var syntax = require('./syntax');
var _ = require('underscore');
var merger = require('./merger');
var readline = require('readline');
var file = require('./file');
var log = require('./_log');
var Hashids = require('hashids');
var hashids = new Hashids(program.LOCALIZATION_ID_HASH_SECRET, program.LOCALIZATION_ID_CHARACTER_LENGTH);

/**
 * Add terminal colors
 */

require('terminal-colors');

/**
 * Update
 *
 * @constructor
 */

function Update() {
  this.isWaitingUserInput = false;
  this.deletedKeys = [];
  this.addedKeys = [];
  this.migratedKeys = [];
  this.rl = null;
}

/**
 * Update keys
 *
 * @return {void}
 * @api public
 */

Update.prototype.run = function() {
  var _this = this;

  this.getNewLocalizations()
    .then(function(newLocalizations) {
      return _this._mergeWithOldLocalizations(newLocalizations);
    })
    .then(function(mergedLocalizations) {
      return file.writeLocalizations(mergedLocalizations)
    })
    .fail(function(error) {
      if(commands.stack && error) {
        console.log(error.stack);
      }

      log.error('Update failed: ' + error.message);
    });
};

/**
 * Strip inner functions calls. All function calls that is not from l10ns
 * needs to be removed. Because they can cause updating error
 * when they are defined inside variables like below
 *
 *    Example:
 *
 *      gt('SOME_TRANSLATION_KEY', {
 *        prop1 : test() // Becomes ''
 *      });
{'fraction_non_alphanumeric': 0.15033091711314214, 'fraction_numerical': 0.0028364323983611725, 'mean_word_length': 3.4391608391608393, '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': '2805483', 'n_tokens_mistral': 986, 'n_tokens_neox': 964, 'n_words': 233}