Skip to content

Commit

Permalink
Bug 1091113 - Don't merge obsolete entity fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibi Braniecki committed Nov 12, 2014
1 parent eb8a140 commit d1984db
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion build/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
throw new L10n.Error('Context not ready');
}

var sourceEntity = this.getLocale('en-US').astById[id];

var cur = 0;
var loc;
var locale;
Expand All @@ -96,7 +98,12 @@
}

if (locale.astById && id in locale.astById) {
return locale.astById[id];
var entity = locale.astById[id];
if (loc === 'en-US' || areEntityStructsEqual(sourceEntity, entity)) {
return entity;
} else {
return sourceEntity;
}
}

var e = new L10n.Error(id + ' not found in ' + loc, id, loc);
Expand Down Expand Up @@ -157,4 +164,21 @@
}
}

function areEntityStructsEqual(entity1, entity2) {
var keys1 = Object.keys(entity1);
var keys2 = Object.keys(entity2);

if (keys1.length !== keys2.length) {
return false;
}

for (var i = 0; i < keys1.length; i++) {
if (keys2.indexOf(keys1[i]) === -1) {
return false;
}
}

return true;
}

})(this);

0 comments on commit d1984db

Please sign in to comment.