我有utils.js文件。
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;
}
Run Code Online (Sandbox Code Playgroud)
我想使用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: …Run Code Online (Sandbox Code Playgroud)