Skip to content

Commit

Permalink
rebuild with extended framework support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamuhl committed Sep 10, 2018
1 parent f90d144 commit dacff34
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 11.8.0

- deeper support for i18nFormats - add getResource function from format

### 11.7.0

- allows defining defaultValues for plurals -> same logic as using pluralsuffixes in translation files [details](https://www.i18next.com/translation-function/plurals#how-to-find-the-correct-plural-suffix) using eg. defaultValue_plural / defaultValue_2 based on request [1096](https://github.com/i18next/i18next/issues/1096)
Expand Down
6 changes: 4 additions & 2 deletions i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,9 @@ var Translator = function (_EventEmitter) {
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;

// object
var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
if (res && handleAsObject && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
if (handleAsObjectInI18nFormat && res && handleAsObject && 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(resUsedKey, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.';
Expand All @@ -677,7 +678,7 @@ var Translator = function (_EventEmitter) {
}
res = copy$$1;
}
} else if (joinArrays && resType === '[object Array]') {
} else if (handleAsObjectInI18nFormat && joinArrays && resType === '[object Array]') {
// array special treatment
res = res.join(joinArrays);
if (res) res = this.extendTranslation(res, keys, options);
Expand Down Expand Up @@ -865,6 +866,7 @@ var Translator = function (_EventEmitter) {
Translator.prototype.getResource = function getResource(code, ns, key) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
return this.resourceStore.getResource(code, ns, key, 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "i18next",
"version": "11.7.0",
"version": "11.8.0",
"description": "i18next internationalization framework",
"main": "./index.js",
"jsnext:main": "dist/es/index.js",
Expand Down
6 changes: 4 additions & 2 deletions src/Translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class Translator extends EventEmitter {
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;

// object
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
if (res && handleAsObject && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
if (handleAsObjectInI18nFormat && res && handleAsObject && 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(resUsedKey, res, options) : `key '${key} (${this.language})' returned an object instead of string.`;
Expand All @@ -109,7 +110,7 @@ class Translator extends EventEmitter {
}
res = copy;
}
} else if (joinArrays && resType === '[object Array]') {
} else if (handleAsObjectInI18nFormat && joinArrays && resType === '[object Array]') {
// array special treatment
res = res.join(joinArrays);
if (res) res = this.extendTranslation(res, keys, options);
Expand Down Expand Up @@ -290,6 +291,7 @@ class Translator extends EventEmitter {
}

getResource(code, ns, key, options = {}) {
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
return this.resourceStore.getResource(code, ns, key, options);
}
}
Expand Down

0 comments on commit dacff34

Please sign in to comment.