Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Bug 1091113 - Don't merge obsolete entity fields. r=stas
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibi Braniecki authored and stasm committed Nov 17, 2014
1 parent aa37c4d commit c81d198
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion bindings/l20n/buildtime.js
Expand Up @@ -83,6 +83,8 @@ L10n.Context.prototype.getEntitySource = function(id) {
throw new L10n.Error('Context not ready');
}

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

var cur = 0;
var loc;
var locale;
Expand All @@ -94,7 +96,12 @@ L10n.Context.prototype.getEntitySource = function(id) {
}

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 @@ -154,3 +161,20 @@ function flushBuildMessages(variant) {
}
}
}

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;
}

0 comments on commit c81d198

Please sign in to comment.