小编Tri*_*ris的帖子

Asp.net 核心本地化 有没有办法允许所有文化?

我想在我的应用程序中允许所有文化。正如你在下面看到的,我允许的文化很少。而且我有一个自定义提供程序,可以了解用户的文化。如果他的文化不在 SupportedCultures 中,那意味着我无法处理他的文化(即使我可以)。在分配 SupportedCultures 之前,我不知道将支持哪些文化。

例如 GetTheUserCulture() 返回“de”。当我稍后尝试使用该文化时,它将回退到默认语言(在本例中为“en”)。或者我希望它是“de”。

有没有办法允许所有文化?

            const string defaultCulture = "en";
            services.Configure<RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo(defaultCulture),
                    new CultureInfo("fr-FR"),
                    new CultureInfo("fr"),
                    new CultureInfo("es"),
                    new CultureInfo("ru"),
                    new CultureInfo("ja"),
                    new CultureInfo("ar"),
                    new CultureInfo("zh"),
                    new CultureInfo("en-GB"),
                    new CultureInfo("en-UK")
                };

                options.DefaultRequestCulture = new RequestCulture(defaultCulture);
                options.SupportedCultures = supportedCultures;
                options.SupportedUICultures = supportedCultures;
                options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
                {
                    return new ProviderCultureResult(GetTheUserCulture());
                }));
            });
Run Code Online (Sandbox Code Playgroud)

c# localization asp.net-core asp.net-core-localization

5
推荐指数
1
解决办法
277
查看次数