Rather than specify a defaultMessage for every FormattedMessage, it would be nice to set the defaultMessage to always be that of a particular language. We know we are always going to have English translations for everything. Specifically I'd like to set the defaultMessage to look at "en-US" if the current locale is missing.
Asked
Active
Viewed 269 times
1 Answers
0
Created a util for this:
export function getDefaultText(id: IntlMessages.FM): string {
return IntlMessages.default["en-US"].hasOwnProperty(id) ? IntlMessages.default["en-US"][id] : ""
}
export function formatMessageId(intl: ReactIntl.InjectedIntl, id: IntlMessages.FM) {
return intl.formatMessage({
id: id,
defaultMessage: getDefaultText(id)
})
}

Lars
- 9,976
- 4
- 34
- 40