简体   繁体   English

如何用.NET语言包测试不同语言的.NET资源?

[英]How to test .NET resources in different languages with .NET language packs?

Looking to implement exception message translation as shown in Exception messages in English?希望实现异常消息翻译,如英文异常消息中所示? I'd like unit tests so this requires being able to produce the messages in a different language.我想要单元测试,所以这需要能够用不同的语言生成消息。 That doesn't quite work out though;但这并不太奏效; code like代码像

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
Console.WriteLine(DirectoryNotFoundException().Message);

Always produces the English version "Attempted to access a path that is not on the disk.".始终生成英文版本“试图访问不在磁盘上的路径。”。

Figuring I'm missing something and following instructions I installed the German .NET Framework 4.7.2 language pack for testing this in an application with TargetFrameworkVersion=v4.7.2 Visual Studio 2017, no change.我发现我遗漏了一些东西并按照说明安装了德语 .NET Framework 4.7.2 语言包,以便在 TargetFrameworkVersion=v4.7.2 Visual Studio 2017 的应用程序中对此进行测试,没有变化。

Wanting to try the same in Visual Studio 2022, with the same application but targetting v4.8, I also tried to install the German .NET Framework 4.8 language pack, but that installer doesn't complete.想在 Visual Studio 2022 中尝试同样的操作,使用相同的应用程序但目标是 v4.8,我还尝试安装德语 .NET Framework 4.8 语言包,但该安装程序未完成。 The tranlated message is (almost ironically the installer UI is completely in German) ".NET Framework 4.8 (Deutsch) or a later version is already installed on this computer."翻译后的消息是(几乎具有讽刺意味的是,安装程序 UI 完全是德语)“此计算机上已安装 .NET Framework 4.8 (Deutsch) 或更高版本。”

Am I doing something wrong here?我在这里做错了什么吗? I mean I can write applications targetting different framework versions so I assume the prerequisites for language packs are there?我的意思是我可以编写针对不同框架版本的应用程序,所以我假设存在语言包的先决条件? Do I need to install something else, or in a different way?我是否需要安装其他东西,或者以不同的方式安装?

And is there a way to figure out in code or otherwise why the GetCultureInfo call doesn't return a culture, eg where does it go looking for resource files, and is there perhaps a way to correct that?有没有办法在代码中或以其他方式弄清楚为什么GetCultureInfo调用不返回文化,例如 go 在哪里寻找资源文件,也许有办法纠正这个问题?

Looks like to get this working, the OS needs to have the wanted language (thanks @PMS for hinting on that): installing the German language ( Start->Add a language to this device ) solved it, even without installing a separate language pack or antything.看起来要让它工作,操作系统需要有所需的语言(感谢@PMS 对此的提示):安装德语( Start->Add a language to this device )解决了它,即使没有安装单独的语言包或任何东西。

And is there a way to figure out in code or otherwise why the GetCultureInfo call doesn't return a culture, eg where does it go looking for resource files有没有办法在代码或其他方面弄清楚为什么 GetCultureInfo 调用不返回文化,例如 go 在哪里寻找资源文件

This remains unasnwered though, but I don't need this anymore now.虽然这仍然没有得到证实,但我现在不再需要它了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM