From b2ce58259f7c902e41b4bf449dadc8e4ee879431 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Sun, 5 Aug 2018 01:10:54 +0300 Subject: [PATCH] Use new localization style in the templates. --- .../DemoAppModule.cs | 25 +++++-------------- .../MyProjectNameWebModule.cs | 20 ++++----------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/DemoAppModule.cs b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/DemoAppModule.cs index 4f4c51a247..02d15c0fa7 100644 --- a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/DemoAppModule.cs +++ b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/DemoAppModule.cs @@ -1,13 +1,9 @@ -using System.Collections.Generic; -using System.Globalization; -using System.IO; +using System.IO; using System.Linq; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using MyCompanyName.MyProjectName.EntityFrameworkCore; using Swashbuckle.AspNetCore.Swagger; using Volo.Abp; @@ -22,6 +18,7 @@ using Volo.Abp.Identity; using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Identity.Web; +using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.SettingManagement.EntityFrameworkCore; @@ -81,17 +78,10 @@ public override void ConfigureServices(ServiceConfigurationContext context) options.DocInclusionPredicate((docName, description) => true); }); - var cultures = new List + context.Services.Configure(options => { - new CultureInfo("en") - //Add other languages... - }; - - context.Services.Configure(options => - { - options.DefaultRequestCulture = new RequestCulture("en"); - options.SupportedCultures = cultures; - options.SupportedUICultures = cultures; + options.Languages.Add(new LanguageInfo("en", "en", "English")); + //...add other languages }); context.Services.AddAssemblyOf(); @@ -110,7 +100,6 @@ public override void OnApplicationInitialization(ApplicationInitializationContex app.UseErrorPage(); } - app.UseStaticFiles(); app.UseVirtualFiles(); app.UseSwagger(); @@ -120,9 +109,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex }); app.UseAuthentication(); - - app.UseRequestLocalization(app.ApplicationServices.GetRequiredService>().Value); - + app.UseAbpRequestLocalization(); app.UseAuditing(); app.UseMvc(routes => diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs index d7315da48d..21f1a0aaa7 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs @@ -1,13 +1,9 @@ -using System.Collections.Generic; -using System.Globalization; -using System.IO; +using System.IO; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using MyCompanyName.MyProjectName.EntityFrameworkCore; using MyCompanyName.MyProjectName.Localization.MyProjectName; using MyCompanyName.MyProjectName.Menus; @@ -122,14 +118,6 @@ private static void ConfigureVirtualFileSystem(IServiceCollection services, IHos private static void ConfigureLocalizationServices(IServiceCollection services) { - var cultures = new List {new CultureInfo("en"), new CultureInfo("tr")}; - services.Configure(options => - { - options.DefaultRequestCulture = new RequestCulture("en"); - options.SupportedCultures = cultures; - options.SupportedUICultures = cultures; - }); - services.Configure(options => { options.Resources @@ -138,6 +126,9 @@ private static void ConfigureLocalizationServices(IServiceCollection services) typeof(AbpValidationResource), typeof(AbpUiResource) ); + + options.Languages.Add(new LanguageInfo("en", "en", "English")); + options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe")); }); } @@ -183,8 +174,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex app.UseVirtualFiles(); app.UseAuthentication(); - - app.UseRequestLocalization(app.ApplicationServices.GetRequiredService>().Value); + app.UseAbpRequestLocalization(); app.UseSwagger(); app.UseSwaggerUI(options =>