in tools/i18n/update.js [194:239]
function updateLanguageXlfJson(sourceHtmlRelativePath, strings) {
return Promise.all(langs.map(function (lang) {
var langJsons = xliffs[lang] || {};
var xlfJson = langJsons[sourceHtmlRelativePath] || {dirty: true};
var existingIDs = xlfJson.items ? Object.getOwnPropertyNames(xlfJson.items) : [];
addXlfJsonProp(xlfJson, 'lang', lang);
addXlfJsonProp(xlfJson, 'original', sourceHtmlRelativePath);
addXlfJsonProp(xlfJson, 'items', {});
var idsRequiringTranslation = [];
strings.forEach(function (string) {
var id = string.id;
var pos = existingIDs.indexOf(id);
if (pos > -1) {
existingIDs.splice(pos, 1);
}
var existingValue = xlfJson.items[id];
if (!existingValue || existingValue.text !== string.text) {
xlfJson.items[id] = {text: string.text, state: NEEDS_TRANSLATION, stateQualifier: MACHINE_SUGGESTION};
xlfJson.dirty = true;
idsRequiringTranslation.push(id);
} else if (existingValue.state === TRANSLATED && existingValue.stateQualifier === MACHINE_SUGGESTION) {
// Remove 'mt-suggestion' state qualifier if item has been translated
delete existingValue.stateQualifier;
xlfJson.dirty = true;
}
});
// If there are any ids left in existingIDs, they should be removed from xlfJson (which will mean they also get
// removed from the xlf file).
if (existingIDs.length) {
xlfJson.dirty = true;
existingIDs.forEach(function (id) {
delete xlfJson.items[id];
});
}
return applyTranslations(xlfJson.items, idsRequiringTranslation, lang).then(function () {
return xlfJson;
});
}));
}