Skip to content

Commit

Permalink
Merge 17659f5 into 47c6f11
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Aug 28, 2018
2 parents 47c6f11 + 17659f5 commit fcbcd96
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
6 changes: 2 additions & 4 deletions dadi/lib/model/collections/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[
"aclv1"
"aclv1",
"i18nv1"
]
50 changes: 49 additions & 1 deletion test/acceptance/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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'])

Expand Down

0 comments on commit fcbcd96

Please sign in to comment.