防止异常消息被翻译成用户的语言?
如何使我的应用程序在显示 win32/.net 异常消息时始终使用英语?
我收到这条消息,看起来有人用 babelfish 翻译它(瑞典语): “System.ComponentModel.Win32Exception:程序在启动后启动了 sida-vid-sidakonfiguration är felaktig。”
非常没有帮助,谷歌上有多达 4 个点击,但没有一个有帮助。 所以我必须猜测原始消息是什么并用谷歌搜索。 (它是:“应用程序无法启动,因为它的并行配置不正确。”)
这一次,找出原始错误消息是什么相当简单,从一开始就有英文消息当然可以节省我的时间。
那么我该怎么做呢?
How do I make my application always use English when displaying win32/.net exceptions messages?
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."
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.")
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试将
Thread.CurrentThread.CurrentUICulture
和/或.CurrentCulture
设置为CultureInfo("en-US")
。You can try setting
Thread.CurrentThread.CurrentUICulture
and/or.CurrentCulture
toCultureInfo("en-US")
.如果是 ASP.NET 应用程序,您可以在 web.config (*) 中设置 UI 语言:
对于其他应用程序,默认使用当前用户的区域设置,您必须显式覆盖它 - 例如 Thread.CurrentUICulture = new文化信息(“en-US”)。
(*) 警告 - 如果配置文件中的错误导致在处理元素之前引发异常,您将获得默认的 uiCulture。
If it's an ASP.NET application, you can set the UI language in web.config (*):
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").
(*) 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.
强制异常以不同的语言显示对用户来说似乎有点苛刻......您可以在消息中显示错误代码吗? 然后用户会得到他们可以理解的内容,您可以查找翻译版本的错误代码。
我不是 .net 人员,所以我不知道这是否可行,只是一个想法。
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.
首先,不要向用户显示 win32/.net 异常消息。 您应该处理异常而不是向用户显示异常。
默认情况下,异常消息将以当前的 UI 语言显示(如果安装了适当的语言包,否则将回退为英语)。 您可以更改异常消息 Thread.CurrentThread.CurrentUICulture< /a> 属性,但是它会影响应用程序的整个 GUI。
First of all, don't show win32/.net exception messages to users. You should handle exceptions rather than showing them to user.
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.