Skip to content

Commit

Permalink
Return boolean values with returnObjects=true
Browse files Browse the repository at this point in the history
  • Loading branch information
Martynas Sapoka committed Nov 20, 2017
1 parent 4c334b8 commit 87332fb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion i18next.js
Expand Up @@ -640,7 +640,7 @@ var Translator = function (_EventEmitter) {
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;

// object
if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
if (res && typeof res !== 'string' && typeof res !== 'boolean' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
if (!options.returnObjects && !this.options.returnObjects) {
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(usedKey, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.';
Expand Down
4 changes: 2 additions & 2 deletions i18next.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "i18next",
"version": "10.0.7",
"version": "10.0.8",
"description": "i18next internationalization framework",
"main": "./index.js",
"jsnext:main": "dist/es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Translator.js
Expand Up @@ -81,7 +81,7 @@ class Translator extends EventEmitter {
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;

// object
if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
if (res && (typeof res !== 'string' && typeof res !== 'boolean') && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
if (!options.returnObjects && !this.options.returnObjects) {
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(usedKey, res, options) : `key '${key} (${this.language})' returned an object instead of string.`;
Expand Down
6 changes: 4 additions & 2 deletions test/translator/translator.translate.returnObject.spec.js
Expand Up @@ -15,8 +15,9 @@ describe('Translator', () => {
common: {
test: ['common_test_en_1', 'common_test_en_2'],
something: {
range: '[{{min}}..{{max}}]'
}
range: '[{{min}}..{{max}}]',
},
boolean: { value: true }
},
special: {
test: ['special_test_en_1', 'special_test_en_2']
Expand Down Expand Up @@ -58,6 +59,7 @@ describe('Translator', () => {
// should not overwrite store value
{args: ['common:something'], expected: { range: '[..]' }},
{args: ['common:something.range', { min: '1', max: '1000' }], expected: '[1..1000]'},
{args: ['common:boolean'], expected: { value: true }},
];

tests.forEach((test) => {
Expand Down

0 comments on commit 87332fb

Please sign in to comment.