Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localize Display attribute in Asp.Net Core 1.0.0?

Tags:

How can i localize Name in Display attribute? For example:

[Display(Name = "Library name")]
public string LibraryName { get; set; }

What should I do with that attribute?

like image 884
Yurii N. Avatar asked Aug 08 '16 15:08

Yurii N.


1 Answers

ASP.NET Core 1.0 does not support out-of-the-box localization based on the new introduced localization approach for the Display attribute. One way to go is to use the prior to ASP.NET Core 1.0 approach for localization with resource files. I have implemented a simple demo project which shows how to localize the display attribute here https://github.com/feradz/ASPNetCoreLocalization/wiki DataAnnotations.resx is used for localizing the Display attribute.

In this approach the display name cannot contain special characters and spaces. For example the display name cannot be Library name but it can be LibraryName

[Display(Name="LibraryName", ResourceType = typeof(Resources.DataAnnotations))]
public string LibraryName { get; set; }
like image 81
feradz Avatar answered Sep 26 '22 16:09

feradz