You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From @pauldotknopf on Friday, April 28, 2017 7:45:21 AM
I am using my own localization engine (using PO/POT/MO files). I am not using resx files or satellite culture assemblies.
How do I localize the DisplayAttribute?
[Display(Name="Test")]
I noticed the ResourceType parameter, and I get it. It uses resource classes. However, I was curious, maybe I could change how this works, via DI or some option/configuration stuff. I set the ResourceType to a dummy class, to see what the callstack was.
InvalidOperationException: Cannot retrieve property 'Name' because localization failed. Type 'MedXStorage.Web.Areas.Public.Features.Account.Models.RegisterViewModel+TestResource' is not public or does not contain a public static string property with the name 'Confirm password'.
System.ComponentModel.DataAnnotations.LocalizableString+<>c__DisplayClass12_0.<GetLocalizableValue>b__1()
System.ComponentModel.DataAnnotations.LocalizableString.GetLocalizableValue()
Microsoft.AspNetCore.Mvc.DataAnnotations.Internal.DataAnnotationsMetadataProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
Microsoft.AspNetCore.Mvc.Internal.DefaultCompositeMetadataDetailsProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_DisplayMetadata()
Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Order()
System.Linq.EnumerableSorter.ComputeKeys(TElement[] elements, int count)
System.Linq.EnumerableSorter.ComputeMap(TElement[] elements, int count)
System.Linq.EnumerableSorter.Sort(TElement[] elements, int count)
System.Linq.OrderedEnumerable.ToList()
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Properties()
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ExpressionMetadataProvider.FromLambdaExpression<TModel, TResult>(Expression<Func<TModel, TResult>> expression, ViewDataDictionary<TModel> viewData, IModelMetadataProvider metadataProvider)
Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpressionProvider.CreateModelExpression<TModel, TValue>(ViewDataDictionary<TModel> viewData, Expression<Func<TModel, TValue>> expression)
It looks like I could possible create some kind of meta-data provider that will look at my DisplayAttributes instances, and attempt to localize them. Is this correct? Is this the recommend way of doing custom localization of Display attributes?
I tried to use the AddDataAnnotationsLocalization extension method when using AddMvc, but for some reason, the IStringLocalizerFactory being passed to the DataAnnotationLocalizerProvider callback was always the default resource-based implementation, regardless of my own IStringLocalizerFactory.
From @pauldotknopf on Friday, April 28, 2017 7:45:21 AM
I am using my own localization engine (using PO/POT/MO files). I am not using resx files or satellite culture assemblies.
How do I localize the
DisplayAttribute
?I noticed the
ResourceType
parameter, and I get it. It uses resource classes. However, I was curious, maybe I could change how this works, via DI or some option/configuration stuff. I set theResourceType
to a dummy class, to see what the callstack was.It looks like I could possible create some kind of meta-data provider that will look at my
DisplayAttributes
instances, and attempt to localize them. Is this correct? Is this the recommend way of doing custom localization ofDisplay
attributes?Copied from original issue: aspnet/Localization#362
The text was updated successfully, but these errors were encountered: