< system.web> .net核心中的全球化 [英] <system.web> globalization in .net core

查看:88
本文介绍了< system.web> .net核心中的全球化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用以下设置来设置上一个应用程序的web.config.

I have been using the following setting the the web.config of my previous application.

<system.web>
  <globalization culture="en-AU" uiCulture="en-AU" />
</system.web>

现在在新的.net核心项目中,我不知道如何将此设置放入appsettings.json文件中.

Now in my new .net core project I don't know how to put this setting in the appsettings.json file.

感谢您的帮助, 尼古拉

Thanks for your help, Nikolai

推荐答案

本地化是在Startup class中配置的,可以在整个应用程序中使用. ConfigureServices中使用AddLocalization方法来定义资源和本地化.然后可以在Configure方法中使用它.在这里,可以定义RequestLocalizationOptions,并使用UseRequestLocalization方法将其添加到堆栈中.

The localization is configured in the Startup class and can be used throughout the application. The AddLocalization method is used in the ConfigureServices to define the resources and localization. This can then be used in the Configure method. Here, the RequestLocalizationOptions can be defined and is added to the stack using the UseRequestLocalization method.

public void ConfigureServices(IServiceCollection services)
{
            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddMvc()
                .AddViewLocalization()
                .AddDataAnnotationsLocalization();

            services.AddScoped<LanguageActionFilter>();

            services.Configure<RequestLocalizationOptions>(
                options =>
                    {
                        var supportedCultures = new List<CultureInfo>
                        {
                            new CultureInfo("en-US"),
                            new CultureInfo("de-CH"),
                            new CultureInfo("fr-CH"),
                            new CultureInfo("it-CH")
                        };

                        options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
                        options.SupportedCultures = supportedCultures;
                        options.SupportedUICultures = supportedCultures;
                    });
}

这篇关于&lt; system.web&gt; .net核心中的全球化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆