Skip to content

Commit

Permalink
Change translations structure
Browse files Browse the repository at this point in the history
  • Loading branch information
garethbowen committed Nov 19, 2018
2 parents 391f838 + 3f68173 commit 685ece9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/fn/upload-custom-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = (projectDir, couchUrl) => {
if(e.status === 404) return newDocFor(fileName);
else throw e;
})
.then(doc => mergeProperties(doc, translations))
.then(doc => overwriteProperties(doc, translations))
.then(doc => db.put(doc));
}));
});
Expand All @@ -42,11 +42,20 @@ function propertiesAsObject(path) {
return vals;
}

function mergeProperties(doc, props) {
if(!doc.values) doc.values = {};

for(const k in props) {
if(props.hasOwnProperty(k)) doc.values[k] = props[k];
function overwriteProperties(doc, props) {
if(doc.default) {
// 3.4.0 translation structure
doc.custom = props;
} else {
// obsolete doc structure
if(!doc.values) {
doc.values = {};
}
for(const k in props) {
if(props.hasOwnProperty(k)) {
doc.values[k] = props[k];
}
}
}

return doc;
Expand Down
2 changes: 1 addition & 1 deletion test/fn/upload-custom-translations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('upload-custom-translations', () => {
.then(doc => {
assert.equal(doc.code, lang);
assert.equal(doc.type, 'translations');
assert.deepEqual(doc.values, expectedTranslations);
assert.deepEqual(doc.custom || doc.values, expectedTranslations);
});
}
});

0 comments on commit 685ece9

Please sign in to comment.