I am working on a Asp.net mvc webSite where the requirement is the user should be able to change language and the page content should be translated automatically. Problem Is : I have used Custom Attribute in My Model for displaying localization like thus : [CommonCustomAttributes.LocalizedDisplayName("Register", "UserEmail")].
LocalizedIdsplayname is Implemented like following: [AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] public sealed class LocalizedDisplayNameAttribute : DisplayNameAttribute { public LocalizedDisplayNameAttribute(string resourceFileName, string keyName) : base(GetMessageFromResource(resourceFileName, keyName)) { }
private static string GetMessageFromResource(string resourceFileName, string keyName)
{
try
{
return CustomLocalizationUtility.GetKeyValue(HttpContext.Current, resourceFileName, keyName);
}
catch (Exception)
{
return "";
}
}
}
So when i switch between languages it does not change .I mean the displayname of the Model where it is used like @Html.LabelFor(m => m.UserEmailAddress, new { @class = "col-md-3 control-label" }).
But in the .cshtml where i have used @placeholder = @CustomLocalizationUtility.GetKeyValue("Register", "EnterEmail") that works fine when i change language. Am i missing something Serious? I have used Cookie for setting current culture and i have also overidden the BeginExecuteCore method in base controller. I have set the Cookie for Current culture from a Action method. Do we need to add extra javascript for JQuery Obstrusive validation and Model Displayname change based on the current culture change?