Created
August 25, 2015 18:12
-
-
Save iam4x/f3c2b6fca0e8d68377d5 to your computer and use it in GitHub Desktop.
Catch missing translations from `react-intl`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IntlMixin } from 'react-intl'; | |
// prevent app to break when translation is missing | |
// add message a la i18n Rails | |
export function getIntlMessage(key) { | |
try { | |
return IntlMixin.getIntlMessage.call(this, key); | |
} catch (error) { | |
const { locale } = this.props; | |
return `translation missing ${locale}: ${key}`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage in a component with babel ES7: