Shortcut key of Xamarin Studio



Some Tips of Localization MVC5

Some tips of localization on UI of MVC5.

1.Create the resource file(.resx), e.g. “product.resx”, If it is chinese, the file name is “product.zh-CN.resx”.  The initialization of the culture can be called in the overridden method “Application_BeginRequest” of “Global.asax.cs”.

protected void Application_BeginRequest(object sender , EventArgs e)
//var culture = CultureInfo.CurrentUICulture;
var culture = new CultureInfo(“zh-CN”);

Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;

//Use the same culture for any newly created threads
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

It is not good to code the culture hard. It can be configured by using “CurrentUICulture”, user can switch the language in the browser settings.

2. For the module class, we can use DataAnnotation to simplize localization by using the annotation class. The display of the attribute of the module will be localized.

[Display(Name="Name", ResourceType = typeof(Resources.Products.Product))]
public string Name { get; set; }

3. For the content of HTML tag, it can be localized by calling Resource class.


If the UI in each action is complicated, the directory of resource files should be created as the same structure as the directory “Views” in order to retrieving the variable quickly for each action.