< div id ="title" >
< h1 > My MVC Application </ h1 >
</ div >
change to
< div id ="title" >
< h1 > <% =ViewRes.SharedStrings.Title %> </ h1 >
</ div >
protected void Application_AcquireRequestState( object sender, EventArgs e)
{
//Create culture info object
CultureInfo ci = new CultureInfo( "en" );
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
public ActionResult ChangeCulture( string lang, string returnUrl)
{
Session[ "Culture" ] = new CultureInfo(lang);
return Redirect(returnUrl);
}
<% = Html.ActionLink( "English" , "ChangeCulture" , "Account" ,
new { lang = "en" , returnUrl = this .Request.RawUrl }, null ) %>
<% = Html.ActionLink( "" , "ChangeCulture" , "Account" ,
new { lang = "ru" , returnUrl = this .Request.RawUrl }, null ) %>
< div id ="logindisplay" >
<% Html.RenderPartial( "LogOnUserControl" ); %>
<% Html.RenderPartial( "CultureChooserUserControl" ); %>
</ div >
protected void Application_AcquireRequestState( object sender, EventArgs e)
{
//
if ( HttpContext .Current.Session != null )
{
CultureInfo ci = (CultureInfo) this .Session[ "Culture" ];
// ,
//
//
if (ci == null )
{
// -
string langName = "en" ;
// HTTP
if ( HttpContext .Current.Request.UserLanguages != null && HttpContext .Current.Request.UserLanguages.Length != 0)
{
//
langName = HttpContext .Current.Request.UserLanguages[0].Substring(0, 2);
}
ci = new CultureInfo(langName);
this .Session[ "Culture" ] = ci;
}
//
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
}
[PropertiesMustMatch( "Password" , "ConfirmPassword" ,
ErrorMessageResourceName = "PasswordsMustMatch" ,
ErrorMessageResourceType = typeof (ValidationStrings))]
public class RegisterModel
{
[Required(ErrorMessageResourceName = "Required" , ErrorMessageResourceType = typeof (ValidationStrings))]
[DisplayName( "Username" )]
public string UserName { get ; set ; }
[Required(ErrorMessageResourceName = "Required" , ErrorMessageResourceType = typeof (ValidationStrings))]
[DataType(DataType.EmailAddress)]
[DisplayName( "Email" )]
public string Email { get ; set ; }
[Required(ErrorMessageResourceName = "Required" , ErrorMessageResourceType = typeof (ValidationStrings))]
[ValidatePasswordLength(ErrorMessageResourceName = "PasswordMinLength" ,ErrorMessageResourceType = typeof (ValidationStrings))]
[DataType(DataType.Password)]
[DisplayName( "Password" )]
public string Password { get ; set ; }
[Required(ErrorMessageResourceName = "Required" , ErrorMessageResourceType = typeof (ValidationStrings))]
[DataType(DataType.Password)]
[DisplayName( "Confirm password" )]
public string ConfirmPassword { get ; set ; }
}
public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
private PropertyInfo _nameProperty;
private Type _resourceType;
public LocalizedDisplayNameAttribute( string displayNameKey)
: base (displayNameKey)
{
}
public Type NameResourceType
{
get
{
return _resourceType;
}
set
{
_resourceType = value ;
// nameProperty, set'
_nameProperty = _resourceType.GetProperty( base .DisplayName, BindingFlags.Static | BindingFlags.Public);
}
}
public override string DisplayName
{
get
{
//,nameProperty null
if (_nameProperty == null )
{
return base .DisplayName;
}
return ( string )_nameProperty.GetValue(_nameProperty.DeclaringType, null );
}
}
}
[PropertiesMustMatch( "Password" , "ConfirmPassword" ,
ErrorMessageResourceName = "PasswordsMustMatch" ,
ErrorMessageResourceType = typeof (ValidationStrings))]
public class RegisterModel
{
[Required(ErrorMessageResourceName = "Required" , ErrorMessageResourceType = typeof (ValidationStrings))]
[LocalizedDisplayName( "RegUsername" , NameResourceType = typeof (Names))]
public string UserName { get ; set ; }
[Required(ErrorMessageResourceName = "Required" ,ErrorMessageResourceType = typeof (ValidationStrings))]
[DataType(DataType.EmailAddress)]
[LocalizedDisplayName( "RegEmail" , NameResourceType = typeof (Names))]
public string Email { get ; set ; }
[Required(ErrorMessageResourceName = "Required" , ErrorMessageResourceType = typeof (ValidationStrings))]
[ValidatePasswordLength(ErrorMessageResourceName = "PasswordMinLength" ,
ErrorMessageResourceType = typeof (ValidationStrings))]
[DataType(DataType.Password)]
[LocalizedDisplayName( "RegPassword" , NameResourceType = typeof (Names))]
public string Password { get ; set ; }
[Required(ErrorMessageResourceName = "Required" , ErrorMessageResourceType = typeof (ValidationStrings))]
[DataType(DataType.Password)]
[LocalizedDisplayName( "RegConfirmPassword" , NameResourceType = typeof (Names))]
public string ConfirmPassword { get ; set ; }
}
* This source code was highlighted with Source Code Highlighter .
[OutputCache(Duration=3600, VaryByParam= "none" )]
public ActionResult Index()
{
ViewData[ "Message" ] = "Welcome to ASP.NET MVC!" ;
return View();
}
public override string GetVaryByCustomString( HttpContext context, string value )
{
if ( value .Equals( "lang" ))
{
return Thread.CurrentThread.CurrentUICulture.Name;
}
return base .GetVaryByCustomString(context, value );
}
[OutputCache(Duration=3600,VaryByParam= "none" , VaryByCustom= "lang" )]
public ActionResult Index()
{
ViewData[ "Message" ] = "Welcome to ASP.NET MVC!" ;
return View();
}
Source: https://habr.com/ru/post/86331/