【发布时间】:2016-04-08 14:50:58
【问题描述】:
我花了大约一周的时间试图了解本地化将如何在 ASP.NET Core 1.0 中工作。我已经测试了很多选项,但我无法使其工作。
我已经阅读了Visual Studio 中的错误,我已经阅读了所有关于它现在如何工作的文章(Article1、Article2、Article3)并且我已经检查和测试了所有关于 example在官方 GitHub 存储库中。
我的目标:
我只想让它像在 ASP.NET MVC 5 中一样工作。
我已经像这样配置了我的 Startup.cs:
配置部分:
var requestLocalizationOptions = new RequestLocalizationOptions
{
// Set options here to change middleware behavior
SupportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("es-ES")
},
SupportedUICultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("es-ES")
}
};
app.UseRequestLocalization(requestLocalizationOptions, defaultRequestCulture: new RequestCulture("en-US"));
配置服务部分:
// Add MVC services to the services container.
services
.AddMvc()
.AddViewLocalization(options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
在我的资源文件夹中,我有我的 .resx 文件。我已经从官方示例中复制了它,但没有办法......没有错误,只是不工作。
如果我测试官方 Repo 的本地化示例,它可以工作。但我无法修改以适应 MVC 6。
我在 GitHub 上为我的代码创建了一个存储库并对其进行了测试。 (https://github.com/chemitaxis/Localization.StackOverflow)
有人可以帮帮我吗?我想很多人都有这些问题。
谢谢!!
【问题讨论】:
标签: asp.net-core