Code Block |
---|
language | xml |
---|
theme | DJangoEmacs |
---|
title | Text from component/tag property: Using a function |
---|
|
<FormattedMessage id="home.logo_alt" defaultMessage='SlideWiki beta logo'>
{
(alt) => <img
className="ui centered image"
src="/assets/images/logo_full.png"
alt={alt}
/>
}
</FormattedMessage> |
OR (as we probably will have this situation a lot):
Code Block |
---|
language | js |
---|
theme | DJangoEmacs |
---|
title | Text from component/tag property: Using a lower-level intl API |
---|
|
class Home extends React.Component {
render() {
...
const messages = defineMessages({
logo_alt: {
id: 'home.logo_alt',
defaultMessage: 'SlideWiki beta logo',
}
});
return (
...
<img
className="ui centered image"
src="/assets/images/logo_full.png"
alt={this.context.intl.formatMessage(messages.logo_alt)}
/>
...
)
}
}
Home.contextTypes = {
intl: React.PropTypes.object.isRequired
};
export default Home; |
Note: The second way is recommended, however if there is only 1-2 cases in your component, the first way is better.