3
我有utils.js文件。React-intl在反應之外定義消息
export function categoryIdToCategoryName(categoryId) {
let name;
switch (categoryId) {
case constants.RISK_CATEGORY_LOW:
name = 'low';
break;
case constants.RISK_CATEGORY_MEDIUM:
name = 'medium';
break;
case constants.RISK_CATEGORY_HIGH:
name = 'high';
break;
case constants.RISK_CATEGORY_CRITICAL:
name = 'critical';
break;
default:
console.warn('see: /utils/risk.js', 'categoryIdToCategoryName:', categoryId);
name = 'unknown';
}
return name;
}
我想翻譯這個文本 - [低,中,高,關鍵]使用https://github.com/yahoo/react-intl。所以我定義了消息
const translations = defineMessages({
riskLow: {
id: 'utils.risk.low',
defaultMessage: 'low',
},
riskMedium: {
id: 'utils.risk.medium',
defaultMessage: 'medium',
},
riskHigh: {
id: 'utils.risk.high',
defaultMessage: 'high',
},
riskCritical: {
id: 'utils.risk.critical',
defaultMessage: 'critical',
}
});
現在什麼是最後一步?
如何將消息傳遞迴該函數?應該有formatMessage
函數,但它只是在反應的上下文中。