gpt4 book ai didi

c# - ASP.NET MVC : Localization issues (wrong resx file for culture)

转载 作者:行者123 更新时间:2023-11-30 12:18:17 25 4
gpt4 key购买 nike

我有一个 Strings.resx 和一个 Strings.nl.resx 文件。第一个包含英语字符串,另一个包含荷兰语字符串。它们是 C# 类库 项目的一部分:Module

 public static string testString()
{
//I Force the culture to always be english
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
return Strings.Hello;
}

当我从一个简单的控制台应用程序调用它们时,它起作用了:

  Console.WriteLine(Module.testString()); //English string gets returned

当我从我的 ASP.NET MVC 应用程序中执行相同操作时,我得到了荷兰语版本...

    public ActionResult testCulture()
{
return Content(Module.testString()); //Dutch string gets returned..?!
}

我使用的是荷兰语 Windows,因此任何自动设置都是荷兰语。但是当文化在类库中被硬编码为 en-us 时,我如何才能获得不同的字符串?

我在这里错过了什么?

最佳答案

您是否在任何地方指定了中性资源语言?如果设置为 "nl""nl-NL",任何未找到的资源请求最终将以获取 "nl"结束 资源。由于您没有 Strings.en-US.resxStrings.en.resx,因此将 CurrentUICulture 设置为 "en- US" 将使系统使用中性资源语言。

关于c# - ASP.NET MVC : Localization issues (wrong resx file for culture),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2425595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com