Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
i18n = (key, values) => {
try {
// Fake IntlMixin context with `messages`, `formats` and `locales`
// into `this.props` and `this.context`
const ctx = { ...IntlMixin, context: this.state, props: this.state }
const messages = IntlMixin.getIntlMessage.call(ctx, key)
return IntlMixin.formatMessage.call(ctx, messages, values)
} catch (error) {
debug('dev')(error)
return `translation missing (${this.state.locales[0]}): ${key}`
}
}
export function getIntlMessage(key, values) {
try {
const messages = i18n.getIntlMessage.call(this, key);
return i18n.formatMessage.call({ ...this, ...i18n }, messages, values);
} catch (error) {
debug('dev')(error);
return `translation missing ${this.props.locale}: ${key}`;
}
}