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}`
}
}
import React, { Component, PropTypes } from 'react';
import { IntlMixin } from 'react-intl';
import requireAuth from 'components/shared/require-auth';
@requireAuth
class Protected extends Component {
static propTypes = {
flux: PropTypes.object.isRequired
}
i18n = IntlMixin.getIntlMessage
componentWillMount() {
const { flux } = this.props;
flux.getActions('helmet')
.update({ title: this.i18n('protected.page-title') });
}
render() {
return (
<div>
<h1>Protected</h1>
<p>secret mesaage</p>
</div>
);
}
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}`;
}
}