Prevent exception messages from being translated into the user's language? [duplicate]
Asked Answered
P

4

35

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?

Paracasein answered 13/10, 2008 at 9:43 Comment(1)
Dup question: Exception messages in English? I know, this question here was asked 3 days earlier, but I voted to close since the other thread seems to have more attention and more recent answers.Carnegie
W
10

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

Washday answered 13/10, 2008 at 9:50 Comment(5)
If you change CurrentCulture, won't that change decimal separators, string sorting, currency symbols, date formats etc? Which will seriously annoy your foreign usersCordoba
Here is the full line: System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");Yezd
Is there another possibility than changing the Culture, since that may be set by the application for translation purposes. The exceptions however shouldn't be translated. Are there any packages to remove on the .Net installation??Perlis
Putting this code just before the exception is logged did not help, it is still logging a translated message.Wondrous
This does not help in all cases. I tried it, some exceptions are translated, some just seem to come from the localized framework...Annam
L
2

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.

Lava answered 13/10, 2008 at 11:6 Comment(0)
A
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.

Angers answered 13/10, 2008 at 11:50 Comment(1)
I'm the recipient of that message, not the user, who probably would not understand the error message even if it was in their language. No user should ever see an exception thrown, so I have to catch it and fix it. I have to translate it from Swedish to English before I can understand it.Paracasein
I
0

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.

Injustice answered 13/10, 2008 at 12:39 Comment(1)
This application is still in testing, so I think a few exceptions shown to the tester is OK. His purpose is to find them after all. I use an external csv language file for all my text strings so hopefully changing the UICulture will not affect the user.Paracasein

© 2022 - 2024 — McMap. All rights reserved.