我試圖直接使用標準<FormattedMessage../>
組件調用格式消息()API之外的comp w/o。如何調用formatMessage()從.json文件加載消息
const locale = 'en';
const messages= defineMessages({
greeting: {
id: 'app.greeting',
message:"some message",
defaultMessage: 'Hello,all',
description: 'Greeting to welcome the user to the app',
}
});
const { intl } = new IntlProvider({locale, messages}).getChildContext();
export function someFunc(key, values) {
return intl.formatMessage({id:'greeting'});
}
以及上面是本地定義的靜態信息,但是我有一個翻譯文件,en.json和ja.json全球存儲,我想從加載的消息。 如何使用defineMessages來做到這一點,以便當我調用formatMessage()時,我應該能夠從resp文件中看到消息,具體取決於所選區域設置... 想法讚賞! 謝謝!