Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/make error handling work #27

Merged
merged 4 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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