Skip to content

Commit

Permalink
Merge pull request #1 from igogo5yo/key_fallback
Browse files Browse the repository at this point in the history
Return key if no source for key
  • Loading branch information
igogo5yo authored Dec 13, 2017
2 parents 8842b34 + d76d125 commit f9421dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
9 changes: 7 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/__tests__/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ describe('NodeIntl test', () => {
});
});


it('should format message', () => {
expect(intl.formatMessage('test')).to.equal(mockMessages.test);
});

it('should return message id if no message', () => {
expect(intl.formatMessage('no_text')).to.equal('no_text');
});
});
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export default class NodeIntl {
}

formatMessage(messageId: string, formats: object = {}) {
const message = new IntlMessageFormat(this.messages[messageId], this.locale);
return message.format(formats);
try {
const message = new IntlMessageFormat(this.messages[messageId], this.locale);
return message.format(formats);
} catch (err) {
return messageId;
}
}
}

0 comments on commit f9421dc

Please sign in to comment.