diff --git a/dadi/lib/model/collections/find.js b/dadi/lib/model/collections/find.js index c60e417e..353ca940 100644 --- a/dadi/lib/model/collections/find.js +++ b/dadi/lib/model/collections/find.js @@ -72,11 +72,9 @@ function find ({ // include a field and request a certain language, we must also include // that corresponding variation). config.get('i18n.languages').forEach(supportedLanguage => { - if (options.fields[field] === 0 || supportedLanguage === language) { - let langField = name + config.get('i18n.fieldCharacter') + supportedLanguage + let langField = name + config.get('i18n.fieldCharacter') + supportedLanguage - queryFields[langField] = options.fields[field] - } + queryFields[langField] = options.fields[field] }) // If we're limiting the fields we're requesting, we need to diff --git a/features.json b/features.json index a8d0e23c..79143dc3 100644 --- a/features.json +++ b/features.json @@ -1,3 +1,4 @@ [ - "aclv1" + "aclv1", + "i18nv1" ] \ No newline at end of file diff --git a/test/acceptance/i18n.js b/test/acceptance/i18n.js index afabe33d..c0e61a31 100644 --- a/test/acceptance/i18n.js +++ b/test/acceptance/i18n.js @@ -319,7 +319,7 @@ describe('Multi-language', function () { }) }) - it('should return the translation version of a field when the fields projection is set to include the field in question', done => { + it('should return the translation version of a field when the fields projection is set to include the field in question (with `lang` param)', done => { config.set('i18n.languages', ['pt', 'fr']) let documents = [ @@ -369,6 +369,54 @@ describe('Multi-language', function () { }) }) + it('should return the translation version of a field when the fields projection is set to include the field in question (without `lang` param)', done => { + config.set('i18n.languages', ['pt', 'fr']) + + let documents = [ + { + title: 'The Little Prince', + 'title:pt': 'O Principezinho', + 'title:fr': 'Le Petit Prince' + }, + { + title: 'The Untranslatable' + } + ] + + client + .post('/v1/library/book') + .set('Authorization', `Bearer ${bearerToken}`) + .send(documents) + .expect(200) + .end((err, res) => { + if (err) return done(err) + + client + .get(`/v1/library/book?fields={"title":1}`) + .set('Authorization', `Bearer ${bearerToken}`) + .expect(200) + .end((err, res) => { + res.body.results.length.should.eql(2) + + let results = res.body.results + + results[0].title.should.eql(documents[0]['title']) + should.not.exist(results[0]._i18n) + results[0]['title:pt'].should.eql(documents[0]['title:pt']) + results[0]['title:fr'].should.eql(documents[0]['title:fr']) + + results[1].title.should.eql(documents[1].title) + should.not.exist(results[1]._i18n) + should.not.exist(results[1]['title:pt']) + should.not.exist(results[1]['title:fr']) + + config.set('i18n.languages', configBackup.i18n.languages) + + done() + }) + }) + }) + it('should return the original version of a field when the requested language is not part of `i18n.languages`', done => { config.set('i18n.languages', ['fr'])