防止异常消息被翻译成用户的语言?

时间:2023-01-20 17:17:53

How do I make my application always use English when displaying win32/.net exceptions messages?

在显示win32/.net异常消息时,如何使应用程序始终使用英语?

I got this message, it looks like someone used babelfish to translate it (it's Swedish): "System.ComponentModel.Win32Exception: Programmet kunde inte starta eftersom programmets sida-vid-sidakonfiguration är felaktig."

我得到了这个信息,看起来好像有人用babelfish翻译了它(这是瑞典语):“System.ComponentModel。例外:程序满足昆德·恩特·斯塔塔·弗特索姆的程序满足了sida-vid-sidakonfiguration ar felaktig。

Extremely unhelpful, and Google had a whopping 4 hits for it, none of them helpful. So I have to guess what the original message was and google that. (It's was: "The application has failed to start because its side-by-side configuration is incorrect.")

非常没有帮助,谷歌有多达4个点击,没有一个是有用的。我得猜一下原始信息是什么,谷歌。(它是:“应用程序未能启动,因为它的并排配置不正确。”)

This time it was fairly simple to find out what the original error message was, having the message in English from the start would of course save me time.

这一次,找出原始错误消息是什么非常简单,从一开始就使用英语消息当然会节省我的时间。

So how do I do that?

怎么做呢?

5 个解决方案

#1


9  

You can try setting Thread.CurrentThread.CurrentUICulture and/or .CurrentCulture to CultureInfo("en-US").

您可以尝试设置Thread.CurrentThread。当前文化和文化信息(en-US)。

#2


3  

All the more reason why the exceptions shouldn't be translated (badly). When logging exceptions, it makes muc more sense to do it in a single language. I can't believe Microsoft didn't think of a way to do this other than UICulture, which is basically a non-option :(

更重要的是,为什么不应该(糟糕地)翻译这些异常。当记录异常时,用一种语言来做muc更有意义。我不敢相信微软没有想到一种方法来实现这一目标,而不仅仅是UICulture,这基本上是一种非选项:(

#3


2  

If it's an ASP.NET application, you can set the UI language in web.config (*):

如果这是一个ASP。NET应用程序,您可以在web中设置UI语言。配置(*):

<system.web>
    <globalization ... uiCulture="en-US" ... />
</system.web>

For other applications, the current user's regional settings are used by default, and you have to explicitly override it - e.g. Thread.CurrentUICulture = new CultureInfo("en-US").

对于其他应用程序,默认情况下使用当前用户的区域设置,您必须显式地覆盖它——例如线程。CurrentUICulture = new CultureInfo(“en - us”)。

(*) caveat - if an error in the config file results in an exception being thrown before the element is processed, you'll get the default uiCulture.

警告-如果配置文件中的错误导致在处理元素之前抛出异常,您将得到默认的uiCulture。

#4


2  

Forcing exceptions to display in a different language seems a bit harsh on the user... can you display an error code along with the message? Then the user will get something they can understand, and you can look up the error code for the translated version.

强制异常以不同的语言显示对用户来说似乎有点苛刻……你能显示一个错误代码与消息一起吗?然后用户将得到他们能够理解的内容,您可以查找翻译版本的错误代码。

I'm not a .net guy so I don't know if this is possible, just an idea.

我不是。net的人,所以我不知道这是否可能,只是个想法。

#5


0  

How do I make my application always use English when displaying win32/.net exceptions messages?

在显示win32/.net异常消息时,如何使应用程序始终使用英语?

First of all, don't show win32/.net exception messages to users. You should handle exceptions rather than showing them to user.

首先,不要向用户显示win32/.net异常消息。您应该处理异常,而不是将它们显示给用户。

By default exception messages will be shown in current's UI language (if appropriate language pack is installed, otherwise they fallback to English). You can change exception messages changing Thread.CurrentThread.CurrentUICulture property, however it will affect the whole GUI of your app.

默认情况下,异常消息将显示在当前的UI语言中(如果安装了适当的语言包,则返回到英语)。可以修改异常消息来更改Thread.CurrentThread。不过,它会影响应用程序的整个GUI。

#1


9  

You can try setting Thread.CurrentThread.CurrentUICulture and/or .CurrentCulture to CultureInfo("en-US").

您可以尝试设置Thread.CurrentThread。当前文化和文化信息(en-US)。

#2


3  

All the more reason why the exceptions shouldn't be translated (badly). When logging exceptions, it makes muc more sense to do it in a single language. I can't believe Microsoft didn't think of a way to do this other than UICulture, which is basically a non-option :(

更重要的是,为什么不应该(糟糕地)翻译这些异常。当记录异常时,用一种语言来做muc更有意义。我不敢相信微软没有想到一种方法来实现这一目标,而不仅仅是UICulture,这基本上是一种非选项:(

#3


2  

If it's an ASP.NET application, you can set the UI language in web.config (*):

如果这是一个ASP。NET应用程序,您可以在web中设置UI语言。配置(*):

<system.web>
    <globalization ... uiCulture="en-US" ... />
</system.web>

For other applications, the current user's regional settings are used by default, and you have to explicitly override it - e.g. Thread.CurrentUICulture = new CultureInfo("en-US").

对于其他应用程序,默认情况下使用当前用户的区域设置,您必须显式地覆盖它——例如线程。CurrentUICulture = new CultureInfo(“en - us”)。

(*) caveat - if an error in the config file results in an exception being thrown before the element is processed, you'll get the default uiCulture.

警告-如果配置文件中的错误导致在处理元素之前抛出异常,您将得到默认的uiCulture。

#4


2  

Forcing exceptions to display in a different language seems a bit harsh on the user... can you display an error code along with the message? Then the user will get something they can understand, and you can look up the error code for the translated version.

强制异常以不同的语言显示对用户来说似乎有点苛刻……你能显示一个错误代码与消息一起吗?然后用户将得到他们能够理解的内容,您可以查找翻译版本的错误代码。

I'm not a .net guy so I don't know if this is possible, just an idea.

我不是。net的人,所以我不知道这是否可能,只是个想法。

#5


0  

How do I make my application always use English when displaying win32/.net exceptions messages?

在显示win32/.net异常消息时,如何使应用程序始终使用英语?

First of all, don't show win32/.net exception messages to users. You should handle exceptions rather than showing them to user.

首先,不要向用户显示win32/.net异常消息。您应该处理异常,而不是将它们显示给用户。

By default exception messages will be shown in current's UI language (if appropriate language pack is installed, otherwise they fallback to English). You can change exception messages changing Thread.CurrentThread.CurrentUICulture property, however it will affect the whole GUI of your app.

默认情况下,异常消息将显示在当前的UI语言中(如果安装了适当的语言包,则返回到英语)。可以修改异常消息来更改Thread.CurrentThread。不过,它会影响应用程序的整个GUI。