Merge pull request #2077 from ErikDakoda/GetLabelIntlFallback

SmartForm.getLabel() intl string fallback
This commit is contained in:
Sacha Greif 2018-09-22 22:54:27 +09:00 committed by GitHub
commit 73d7172896
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -423,7 +423,18 @@ class SmartForm extends Component {
*/
getLabel = (fieldName, fieldLocale) => {
const collectionName = this.getCollection().options.collectionName.toLowerCase();
const intlLabel = this.context.intl.formatMessage({ id: `${collectionName}.${fieldName}` });
const defaultMessage = '|*|*|';
let id = `${collectionName}.${fieldName}`;
let intlLabel;
intlLabel = this.context.intl.formatMessage({ id, defaultMessage });
if (intlLabel === defaultMessage) {
id = `global.${fieldName}`;
intlLabel = this.context.intl.formatMessage({ id });
if (intlLabel === defaultMessage) {
id = fieldName;
intlLabel = this.context.intl.formatMessage({ id });
}
}
const schemaLabel = this.state.flatSchema[fieldName] && this.state.flatSchema[fieldName].label;
const label = intlLabel || schemaLabel || fieldName;
if (fieldLocale) {