Пример #1
0
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder applicationBuilder)
        {
            var supportedCultures = new[]
            {
                new System.Globalization.CultureInfo("fa-IR"),
                new System.Globalization.CultureInfo("en-US"),
            };

            var options = new Microsoft.AspNetCore.Builder.RequestLocalizationOptions
            {
                DefaultRequestCulture =
                    new Microsoft.AspNetCore.Localization.RequestCulture(culture: "en-US", uiCulture: "en-US"),

                SupportedCultures = supportedCultures,

                SupportedUICultures = supportedCultures
            };

            // Install-Package Microsoft.AspNetCore.Localization.Routing
            // https://github.com/aspnet/Docs/tree/master/aspnetcore/mvc/controllers/filters/sample

            options.RequestCultureProviders =
                new[]
            {
                new Microsoft.AspNetCore.Localization.Routing.RouteDataRequestCultureProvider()
                {
                    Options = options
                }
            };

            applicationBuilder.UseRequestLocalization(options);
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var locale = Configuration["SiteLocale"];
            RequestLocalizationOptions localizationOptions = new RequestLocalizationOptions
            {
                SupportedCultures = new List <CultureInfo> {
                    new CultureInfo(locale)
                },
                SupportedUICultures = new List <CultureInfo> {
                    new CultureInfo(locale)
                },
                DefaultRequestCulture = new RequestCulture(locale)
            };

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseRequestLocalization(localizationOptions);

            app.UseStaticFiles();

            //app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
 /// <summary>
 /// Adds a provider that will be resolved during the request via DI
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="options"></param>
 /// <remarks>This method ensures that injected provider has priority over other <see cref="RequestCultureProvider"/> instances in <see cref="RequestLocalizationOptions.RequestCultureProviders"/>.</remarks>
 public static RequestLocalizationOptions AddInitialInjectedProvider <T>(this RequestLocalizationOptions options)
     where T : IRequestCultureProvider
 {
     options.RequestCultureProviders.Insert(0, new RequestCultureProviderInjectionAdapter <T>());
     return(options);
 }