/// <summary> /// Tranform <see cref="ModelMetadata"/> /// </summary> /// <param name="metadata"></param> public static void Transform([NotNull] ModelMetadata metadata) { Invariant.IsNotNull(metadata, "metadata"); var containerType = metadata.ContainerType; if (!LocalizationConventions.Enabled || containerType == null || string.IsNullOrEmpty(metadata.PropertyName)) { return; } // flent configuration does not have ResourceType, so get it from type var resourceType = LocalizationConventions.GetDefaultResourceType(containerType); var propertyName = metadata.PropertyName; if (resourceType != null && !string.IsNullOrEmpty(propertyName)) { var key = ResourceUtil.GetResourceKey(containerType, propertyName); if (metadata.DisplayName == null) { metadata.DisplayName = RetrieveValue(resourceType, key, propertyName); } if (metadata.ShortDisplayName == null) { metadata.ShortDisplayName = RetrieveValue(resourceType, key + ShortDisplayNameSuffix, propertyName + ShortDisplayNameSuffix); } if (metadata.Watermark == null) { metadata.Watermark = RetrieveValue(resourceType, key + PromptSuffix, propertyName + PromptSuffix); } if (metadata.Description == null) { metadata.Description = RetrieveValue(resourceType, key + DescriptionSuffix, propertyName + DescriptionSuffix); } } }
/// <summary> /// /// </summary> /// <param name="attr"></param> /// <param name="containerType"></param> /// <param name="propertyName"></param> /// <param name="defaultResourceType"></param> public static void Transform([NotNull] DisplayAttribute attr, [NotNull] Type containerType, string propertyName, Type defaultResourceType) { Invariant.IsNotNull(attr, "displayAttribute"); var resourceType = attr.ResourceType ?? defaultResourceType; if (resourceType == null) { return; } // reset resource and manually set values attr.ResourceType = null; var resourceKey = ResourceUtil.GetResourceKey(containerType, propertyName); // retrieve values attr.Name = GetValue(resourceType, attr.Name, resourceKey, propertyName); attr.Description = GetValue(resourceType, attr.Description, resourceKey + DescriptionSuffix, propertyName + DescriptionSuffix); attr.ShortName = GetValue(resourceType, attr.ShortName, resourceKey + ShortDisplayNameSuffix, propertyName + ShortDisplayNameSuffix); attr.Prompt = GetValue(resourceType, attr.Prompt, resourceKey + PromptSuffix, propertyName + PromptSuffix); attr.GroupName = GetValue(resourceType, attr.GroupName, null, null); // leave original behaviour }