简体   繁体   English

.NET 核心系统异常本地化不起作用

[英].NET Core system exception localization not working

What is the status and design regarding localization of system exception messages in .NET Core (.NET 5)? .NET Core (.NET 5) 中系统异常消息本地化的现状和设计是什么? Are they supposed to be localized?他们应该本地化吗? Is there something like "language packs" that can be installed for the .NET Core runtime?是否可以为 .NET 核心运行时安装类似“语言包”的东西?

Localization/translation of system exception messages it not working in .NET 5.系统异常消息的本地化/翻译在 .NET 5 中不起作用。

I have the following code:我有以下代码:

static void Main()
{
    var culture = new CultureInfo("de-DE");
    CultureInfo.CurrentUICulture = culture;

    var nre = new NullReferenceException();
    Console.WriteLine(nre);
}

This always produces English output (at least when running on Windows with English as the primary language) when running on .NET 5, no matter what I set the CurrentUICulture (or CurrentCulture ) to.当在 .NET 5 上运行时,无论我将CurrentUICulture (或 CurrentUICulture 设置为什么)(或 CurrentUICulture),这始终会产生英语 output(至少在以英语为主要语言的CurrentCulture上运行时)。

System.NullReferenceException: Object reference not set to an instance of an object.

This used to be different on .NET Framework, at least when the target language pack is installed.这曾经在 .NET 框架上有所不同,至少在安装目标语言包时是这样。 Here's what I get when I change TargetFramework from net5.0 to eg net462 in the .csproj file:这是我在.csproj文件中将TargetFrameworknet5.0更改为net462时得到的结果:

System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

I had a look into the source code of the NullReferenceException class and it seems to be prepared for localization.我查看了 NullReferenceException class 的源代码,它似乎已准备好进行本地化。 At least it retrieves the error message from some StringResources.至少它从一些 StringResources 中检索错误消息。 But up to now there are only English resources available .但到目前为止, 只有英文资源可用 Or did I miss something?还是我错过了什么?

According to https://github.com/microsoft/dotnet/issues/474 the .NET Core has no localized messages.根据https://github.com/microsoft/dotnet/issues/474,.NET核心没有本地化消息。 Not sure if it will continue to be that way in .NET, but at least that explains the difference in .NET 5 responses.不确定在 .NET 中是否会继续这样,但至少这解释了 .NET 5 响应的差异。

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

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