Prevent exception messages from being translated into the user's language?

后端 未结 5 1703
遇见更好的自我
遇见更好的自我 2020-12-14 00:41

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

相关标签:
5条回答
  • 2020-12-14 01:06

    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 :(

    0 讨论(0)
  • 2020-12-14 01:06

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

    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.

    0 讨论(0)
  • 2020-12-14 01:10

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

    <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").

    (*) 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.

    0 讨论(0)
  • 2020-12-14 01:19

    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.

    0 讨论(0)
  • 2020-12-14 01:21

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

    0 讨论(0)
提交回复
热议问题