强制例外语言为英语 [英] Force exceptions language in English

查看:18
本文介绍了强制例外语言为英语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Visual Studio 2005 是一个法语版本,安装在法语操作系统上.我在调试或运行时收到的所有异常也是用法语获得的.

但是,我可以做一些例外消息是英语的事情吗?用于观察、讨论等.

我尝试了以下方法:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");抛出新的 NullReferenceException();

获得

<块引用>

对象引用未设置为对象的实例.

这当然很酷...但是,当我在一个法语项目上工作时,我不会将 Thread.CurrentUICulture 硬编码为英语.我希望英语更改仅在我的本地计算机上,并且不要更改项目属性.

是否可以在不修改应用程序的代码的情况下设置异常语言?

<小时>

在 VS 2008 中,将工具 -> 选项 -> 环境 -> 国际设置 -> 语言设置为英语",然后抛出相同的异常获取法语的 ex 消息,但是:替代文字 http://lh4.ggpht.com/_1TPOP7DzY1E/S1V62xcvHAI/AAAAAAAC7o/ckLDVFPKh5Y/s800/exception.png

解决方案

最后一个尖锐"的解决方案可能如下:

[STAThread]静态无效主要(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);#如果调试//添加这个;更改语言环境(英语-美国):完成.Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;#万一应用程序.运行(新 Form1());}

但是我想要一个无需修改项目代码的解决方案.

来自 MSDN:p><块引用>

CurrentUICulture 属性将是如果应用程序执行,则隐式设置指定一个CurrentUICulture.如果CurrentUICulture 没有明确设置在应用程序的代码中,它由GetUserDefaultUILanguage 函数在 Windows 2000 和 Windows XP 上多语言用户界面 (MUI)最终用户可以设置的产品默认语言.如果用户的 UI语言未设置,它将由系统安装的语言,它是操作的语言系统资源.

如果应用程序是基于 Web 的,则CurrentUICulture 可以显式设置在应用程序代码到用户的浏览器接受语言.

My Visual Studio 2005 is a French one, installed on a French OS. All the exceptions I receive during debug or runtime I obtain also in French.

Can I however do something that the exceptions messages be in English? For goggling, discussing etc.

I tried the following:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
throw new NullReferenceException();

obtained

Object reference not set to an instance of an object.

This is, surely, cool... but, as I work on a French project, I will not hardcode forcing Thread.CurrentUICulture to English. I want the English change to be only on my local machine, and don't change the project properties.

Is it possible to set the exceptions language without modifying the code of the application?


In VS 2008, set the Tools -> Options -> Environment -> International Settings -> Language to "English" wnd throwing the same exception obtain the ex message en French, however: alt text http://lh4.ggpht.com/_1TPOP7DzY1E/S1V62xcvHAI/AAAAAAAAC7o/ckLDVFPKh5Y/s800/exception.png

解决方案

Finally a "sharp" solution could be the following:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

#if DEBUG
    // Add this; Change the Locales(En-US): Done.
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
#endif

    Application.Run(new Form1());
}

However I'd like a solution without modifications in the project code.

From MSDN:

The CurrentUICulture property will be set implicitly if an application does specify a CurrentUICulture. If CurrentUICulture is not set explicitly in an application's code, it is set by the GetUserDefaultUILanguage function on Windows 2000 and Windows XP Multilingual User Interface (MUI) products where the end user can set the default language. If the user's UI language is not set, it will be set by the system-installed language, which is the language of the operating system's resources.

If an application is Web-based, the CurrentUICulture can be set explicitly in application code to the user's browser accept language.

这篇关于强制例外语言为英语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆