<commit_before>function I18nKeyStore(options){
  options = options || {}
  this.scope = options.scope;
  this.translations = {};
}

I18nKeyStore.prototype.set = function(key, value){
  if (key.indexOf('#') !== -1){
    key = key.replace('#', '');
  } else if (this.scope) {
    key = this.scope + '.' + key;
  }
  var path = key.split('.');
  var context = this.expandPath(path, key);
  var finalKey = path[path.length - 1];

  if (!context[finalKey]) {
    context[finalKey] = value;
  } else {
    if (typeof context[finalKey] === 'object') {
      throw new Error(key + ' used as both scope and a key');
    }
    throw new Error('cannot reuse key ' + key);
  }
};

I18nKeyStore.prototype.expandPath = function(path, originalKey){
  var trans = this.translations;

  path = path.slice(0, -1);

  path.forEach(function(key){
    if (typeof trans[key] === 'string') {
      throw new Error(originalKey + ' used as both scope and a key');
    }
    trans = trans[key] = {};
  });
  return trans;
};

export default I18nKeyStore;<commit_msg>dont overwrite nested objects in i18n key store<commit_after>function I18nKeyStore(options){
  options = options || {}
  this.scope = options.scope;
  this.translations = {};
}

I18nKeyStore.prototype.set = function(key, value){
  if (key.indexOf('#') !== -1){
    key = key.replace('#', '');
  } else if (this.scope) {
    key = this.scope + '.' + key;
  }
  var path = key.split('.');
  var context = this.expandPath(path, key);
  var finalKey = path[path.length - 1];

  if (!context[finalKey]) {
    context[finalKey] = value;
  } else {
    if (typeof context[finalKey] === 'object') {
      throw new Error(key + ' used as both scope and a key');
    }
    throw new Error('cannot reuse key ' + key);
  }
};

I18nKeyStore.prototype.expandPath = function(path, originalKey){
  var trans = this.translations;

  path = path.slice(0, -1);

  path.forEach(function(key){
    if (typeof trans[key] === 'string') {
      throw new Error(originalKey + ' used as both scope and a key');
    }
    trans = trans[key] = trans[key] || {};
  });
  return trans;
};

export default I18nKeyStore;
{'fraction_non_alphanumeric': 0.16823308270676693, 'fraction_numerical': 0.012218045112781954, 'mean_word_length': 3.258, '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': '1739331', 'n_tokens_mistral': 732, 'n_tokens_neox': 710, 'n_words': 183}