MVC III §Slavomír Moroz §2015 Localization §CultureInfo •Provides information about a specific culture (the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers…) • §System.Threading.Thread properties: •Culture - number and date formats, currency symbols, sort order, casing etc. •UICulture - resource localization (string tranlastions) • §Resource files (resx) naming conventions •name.resx – used as default when culture specific resource was not found •name.[language].resx – specific (strings.en.resx) •name.[language]-[region].resx – more specific (strings.en-us.resx) • §https://msdn.microsoft.com/en-us/library/ms247246.aspx § § • • • • • §MVC III •Create resource file, show types of resources, explain embedded resources. •Show string resource types •Modifier public, CodeGenerator •Show GamesStore.Resources project Working with resources §View •@[Namespace].[ResourceName].[StringName] ("@Resources.Resources.LogOn ") •You can add this namespace to the views Web.config and type "@Resources.LogOn“ • §Data annotations §[Display(Name = "FirstName", ResourceType = typeof(Resources.Resources))] §[Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "FirstNameRequired")] §[StringLength(50, ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "FirstNameLong")] §public string FirstName { get; set; } §MVC III •Explain namespace generation. Custom namespace. •Show prepared data annotations and views (GamesViewModel and Create / edit views) •Show nested web.config and explain namespaces for views •Show that it works, use auto culture detection. Determining culture §MVC III •Give info that auto culture detection might be dangerous for not recognized cultures. Define list of supported cultures and check against it. Auto UICulture is not that dangerous. It will fallback to default resource file. But if your site is not designed to work with given culture then you want to use the one it was designed for. (date format, currencies) •Remove auto culture •Cookie •Show CultureHelper, CultureController and partial view. •Add change culture option to layout (@Html.Action("CultureHeaderPartial", "Culture") place befor login in header) •Show HttpApplication events & lifecycle poster •Add AcquireRequestState code to set up culture •URL •Create new routes •Redirect to Index (games controller) •Modify CultureConfig •Modify Switch action in CultureController •Login redirect from owin to culture controller •Login redirect in culture controller Localization resources •ASP.NET MVC 5 Internationalization • •Selecting Cultures for Localization in ASP.NET • •ASP.NET MVC 5 Internationalization · Date and Time •ASP.NET MVC 5 Internationalization · How to Store Strings in a Database or Xml • •Globalization, Internationalization and Localization in ASP.NET MVC 3, JavaScript and jQuery • •Internationalization • •Localization § §MVC III Bundling & minification •Nuget Microsoft.AspNet.Web.Optimization • §Register •BundleTable.Bundles.Add() •Pass StyleBundle / ScriptBundle object § §Render •Use namespace System.Web.Optimization •@Styles.Render("~/BundleName") •@Scripts.Render("~/BundleName") § §Debug •Bundling & minification is disabled in debug mode (configured in web.config) •You can override this behavior by setting BundleTable.EnableOptimizations property. § § §http://www.asp.net/mvc/overview/performance/bundling-and-minification §MVC III •Install nugget (already installed in prepared demo project) •Create BundleConfig for layout without EnableOptimization •Add namespace to views web.cofig or use in layout (System.Web.Optimization) •Render bundles •Show site, nothing happens because of debug enabled •EnableOptimization, now bundles are forced