Skip to content

Commit

Permalink
Merge pull request #27 from sidoruk-sv/fix/make-error-handling-work
Browse files Browse the repository at this point in the history
Fix/make error handling work
  • Loading branch information
jamuhl authored Jun 12, 2020
2 parents 93d45e9 + 90ed6e6 commit acc26e1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ i18next
// which events on resourceSource should clear the cache, can be set to false or string of events separated by " "
bindI18nStore: '',

// Will be run when parser throws an error. Return a string to use in place of the translation.
// Will be run when parser throws an error. Can return any string, which can be used as a fallback, in case of broken translation.
// If omitted, the default swallows the error and returns the unsubstituted string (res)
parseErrorHandler: (err, key, res, options) => {}
}
Expand Down
12 changes: 6 additions & 6 deletions i18nextICU.js
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ var ICU = /*#__PURE__*/function () {
}, {
key: "addUserDefinedFormats",
value: function addUserDefinedFormats(formats) {
this.formats = this.formats ? _objectSpread2({}, this.formats, {}, formats) : formats;
this.formats = this.formats ? _objectSpread2(_objectSpread2({}, this.formats), formats) : formats;
}
}, {
key: "parse",
Expand All @@ -2151,12 +2151,12 @@ var ICU = /*#__PURE__*/function () {
fc = getPath(this.mem, memKey);
}

if (!fc) {
fc = new MessageFormat(res, lng, this.formats);
if (this.options.memoize && (this.options.memoizeFallback || !info || hadSuccessfulLookup)) setPath(this.mem, memKey, fc);
}

try {
if (!fc) {
fc = new MessageFormat(res, lng, this.formats);
if (this.options.memoize && (this.options.memoizeFallback || !info || hadSuccessfulLookup)) setPath(this.mem, memKey, fc);
}

return fc.format(options);
} catch (err) {
return this.options.parseErrorHandler(err, key, res, options);
Expand Down
Loading

0 comments on commit acc26e1

Please sign in to comment.