You can use resource files to do localization Add a Resource File (you can use the Add New Item wizard through Visual Studio - lets call it MyResourcesType. Resx) to your project. Then add your validation messages like this: Required( ErrorMessageResourceType = typeof(MyResourcesType), ErrorMessageResourceName = "MyMessageIdOnTheResourcesFile") From now on changing the language is just a matter adding new resources files.
Check this question's first answer By the way don't use DisplayNameAttribute but DisplayAttribute from System.ComponentModel. DataAnnotations namespace. It's the attribute used by MVC and you can do localization on it too: Display( ResourceType = typeof(MyResourcesType), Name = "MyPropertyIdOnResourcesFile_Name", ShortName = "MyPropertyIdOnResourcesFile_ShortName", Description = "MyPropertyIdOnResourcesFile_Description").
You can use resource files to do localization. Add a Resource File (you can use the Add New Item wizard through Visual Studio - lets call it MyResourcesType. Resx) to your project.
Then add your validation messages like this: Required( ErrorMessageResourceType = typeof(MyResourcesType), ErrorMessageResourceName = "MyMessageIdOnTheResourcesFile") From now on changing the language is just a matter adding new resources files. Check this question's first answer. By the way don't use DisplayNameAttribute but DisplayAttribute from System.ComponentModel.
DataAnnotations namespace. It's the attribute used by MVC and you can do localization on it too: Display( ResourceType = typeof(MyResourcesType), Name = "MyPropertyIdOnResourcesFile_Name", ShortName = "MyPropertyIdOnResourcesFile_ShortName", Description = "MyPropertyIdOnResourcesFile_Description").
I wouldn't merely say that you can use resource files for this; that is the way you are supposed to handle localization in .NET. – Aaronaught Oct 30 at 4:26 thank you guys I posted my solution at below – Orhaan Oct 30 at 18:25.
The way attributes work is that they are statically compiled into the code. Thus, you cannot have any dynamic functionality like that when using attributes. Jota's answer is the recommended way to do things, however if you're determined to use your own solution you could create your own attribute, and in that attribute you could add code that looks up the messages.
I have a workaround creating my custom @Html.LabelFor() and @html.DescriptionFor() helper. My helper: namespace MyCMS. Helpers { public static class Html { public static MvcHtmlString DescriptionFor( this HtmlHelper self, Expression expression) { var metadata = ModelMetadata.
FromLambdaExpression(expression, self. ViewData); var description = Localizer. Translate(metadata.
Description); return MvcHtmlString. Create(string. Format(@"{0}", description)); } public static MvcHtmlString LabelFor( this HtmlHelper self, Expression expression, bool showToolTip ) { var metadata = ModelMetadata.
FromLambdaExpression(expression, self. ViewData); var name = Localizer. Translate(metadata.
DisplayName); return MvcHtmlString. Create(string. Format(@"{1}", metadata.
PropertyName, name)); } } } my view is: @using MyCMS. Localization; @using MyCMS. Helpers; @Html.
LabelFor(model => model.RecordDetails. TitleAlternative) @Html. TextBoxFor(model => model.RecordDetails.
TitleAlternative, new { @class = "xxlarge" }) @Html. ValidationMessageFor(model => model.RecordDetails. TitleAlternative) @Html.
DescriptionFor(model => model.RecordDetails. TitleAlternative) and I can use my localization approach :) Thanks everyone again...
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.