I have a component that needs strings from the backend. I currently request the .po
file from the server, convert it to .json
and return it to my React component. I then want to be able to display those strings whilst replacing the correct values in the string, i.e.
<FormattedMessage id={dynamicId} values={dynamicVals} />
dynamicId is pulled from a separate api call, as well as dynamicVals.
My problem is that these strings are not bundled like all of my other app strings, so react-intl
is unaware of them. How can I add these strings to the library client-side/async? I've attempted using defineMessages
and addLocaleData
, but I either am doing something incorrectly, or am not using the right api methods. Does addLocaleData
provide the means to adding strings to the library? Is this possible to do?
In summary:
How can I receive
{
notifications.friendships.nowfriends: "{name} is now your friend"
}
from the api and display it using:
<FormattedMessage id='notifications.friendships.nowfriends' values={{ name: 'StackOver Bro' }} />
Thanks for the help in advance.