ASP.NET Core + resx - 仅适用于默认文化

时间:2016-05-18 16:34:34

标签: localization asp.net-core

我正在尝试将WebForm应用程序移植到MVC 6,并且遇到从resx文件获取资源的问题。控制器类中的代码仅返回默认的resx值。

我尝试设置Thread.CurrentThread.CurrentCulture& Thread.CurrentThread.CurrentUICulture以及将Resources.MyResouces.Culture设置为特定文化,但Resources.MyResouces.Key仍然只返回默认值。可能是什么问题?

public IActionResult MyAction(){
    Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = 
        Resources.test.Culture = CultureInfo.GetCultureInfo("fr-FR");

    // The line below still returns the default English resource value
    var localizedValue = Resources.test.test_key;
}

1 个答案:

答案 0 :(得分:0)

WebForms到Asp.Net Core是一个非常巨大的飞跃。我建议从GitHub上的Asp.Net Core localization sample开始,以更清楚地了解它是如何工作的。

特别是,您可能需要在Startup.cs文件中进行更多配置。