Skip to content

Commit

Permalink
Feat/intl report hook (#139)
Browse files Browse the repository at this point in the history
* feat: Add hooks before get and getHTML methods to execute custom methods

* feat: Add fault tolerance to hook functions
  • Loading branch information
dreamWB committed Aug 21, 2020
1 parent df9ee46 commit 7d76152
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ReactIntlUniversal.js
Expand Up @@ -33,7 +33,11 @@ class ReactIntlUniversal {
*/
get(key, variables) {
if (this.options.intlGetHook) {
this.options.intlGetHook(key, this.options.currentLocale);
try {
this.options.intlGetHook(key, this.options.currentLocale);
} catch (e) {
console.log('intl get hook error: ', e);
}
}
invariant(key, "key is required");
const { locales, currentLocale, formats } = this.options;
Expand Down Expand Up @@ -98,7 +102,11 @@ class ReactIntlUniversal {
*/
getHTML(key, variables) {
if (this.options.intlGetHook) {
this.options.intlGetHook(key, this.options.currentLocale);
try {
this.options.intlGetHook(key, this.options.currentLocale);
} catch (e) {
console.log('intl get hook error: ', e);
}
}
let msg = this.get(key, variables);
if (msg) {
Expand Down

0 comments on commit 7d76152

Please sign in to comment.