-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String without FormattedMessage #749
Comments
If I understand your question correctly, you can use the formatMessage function of the API : https://github.com/yahoo/react-intl/wiki/API#formatmessage |
Just add:
Then you will have access to this.context.intl object on your component. Then, simply use: |
Using |
Here is another (a shorter) solution
|
@ericf you know, I'm using the way you've mentioned at the moment but it kinda sucks that we have to use HoC, then props and so on don't you think? I'm wondering if this would be possible just to import a function from which component is not dependent and use it. Probably testing would be also easier then. What do you think guys? |
@krzywiecki I agree with you. It's a very roundabout way of doing things and I think this should be accomplished using simpler methods. |
Thanks @alexander-elgin |
@krzywiecki +1. @ericf any comments on that? |
import { useIntl, FormattedMessage } from 'react-intl';
const MyComponent = () => {
const { formatMessage } = useIntl();
return (
<div>
<span title={formatMessage({id: 'my.message.key'})} />
<FormattedMessage id="my.message.key" />
</div>
);
} |
I want to populate a placeholder in a form with a string based on the locale. How can I retrieve the string without using FormattedMessage?
The text was updated successfully, but these errors were encountered: