Skip to content

Commit

Permalink
allow empty string for array join
Browse files Browse the repository at this point in the history
  • Loading branch information
jamuhl committed Feb 7, 2019
1 parent 51bb65e commit 54da34f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
### 14.1.1

- allow empty string for array join [1191](https://github.com/i18next/i18next/issues/1191)

### 14.1.0

- support plurals in returning objecttree array [1196](https://github.com/i18next/i18next/issues/1196)
Expand Down
4 changes: 2 additions & 2 deletions i18next.js
Expand Up @@ -672,7 +672,7 @@ var Translator = function (_EventEmitter) {
// object
var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && 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(resUsedKey, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.';
Expand All @@ -695,7 +695,7 @@ var Translator = function (_EventEmitter) {
}
res = copy$$1;
}
} else if (handleAsObjectInI18nFormat && joinArrays && resType === '[object Array]') {
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
// array special treatment
res = res.join(joinArrays);
if (res) res = this.extendTranslation(res, keys, options);
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": "14.1.0",
"version": "14.1.1",
"description": "i18next internationalization framework",
"main": "./index.js",
"types": "index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/Translator.js
Expand Up @@ -114,7 +114,7 @@ class Translator extends EventEmitter {
res &&
handleAsObject &&
noObject.indexOf(resType) < 0 &&
!(joinArrays && resType === '[object Array]')
!(typeof joinArrays === 'string' && resType === '[object Array]')
) {
if (!options.returnObjects && !this.options.returnObjects) {
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
Expand Down Expand Up @@ -143,7 +143,7 @@ class Translator extends EventEmitter {
}
res = copy;
}
} else if (handleAsObjectInI18nFormat && joinArrays && resType === '[object Array]') {
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
// array special treatment
res = res.join(joinArrays);
if (res) res = this.extendTranslation(res, keys, options);
Expand Down
4 changes: 4 additions & 0 deletions test/translator/translator.translate.array.spec.js
Expand Up @@ -52,6 +52,10 @@ describe('Translator', () => {
args: ['translation:test', { myVar: 'test', joinArrays: '+' }],
expected: 'test_en_1+test_en_2+test',
},
{
args: ['translation:test', { myVar: 'test', joinArrays: '' }],
expected: 'test_en_1test_en_2test',
},
{
args: [['search.flagList', 'flagList'], {}],
expected: [['basic', 'Basic'], ['simple', 'Simple']],
Expand Down

0 comments on commit 54da34f

Please sign in to comment.