Skip to content

Commit

Permalink
fix: interpolation with data model "replace"
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jan 2, 2023
1 parent 54e8efe commit 10153eb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 22.4.7

- fix: interpolation with data model "replace"

## 22.4.6

- types: missing dir function export for typescript
Expand Down
2 changes: 1 addition & 1 deletion i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@
var nb = res.match(this.interpolator.nestingRegexp);
nestBef = nb && nb.length;
}
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
var data = options.replace && typeof options.replace !== 'string' && this.options.compatibilityAPI === 'v1' ? options.replace : options;
if (this.options.interpolation.defaultVariables) data = _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), data);
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
if (skipOnVariables) {
Expand Down
2 changes: 1 addition & 1 deletion i18next.min.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/Translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,12 @@ class Translator extends EventEmitter {
}

// interpolate
let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
let data =
options.replace &&
typeof options.replace !== 'string' &&
this.options.compatibilityAPI === 'v1'
? options.replace
: options;
if (this.options.interpolation.defaultVariables)
data = { ...this.options.interpolation.defaultVariables, ...data };
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
Expand Down

0 comments on commit 10153eb

Please sign in to comment.