My Blog

Unlocalize .NET messages

by lupok on giovedì 3 gennaio 2013 13:31

Per evitare che il framework .NET mostri messaggi in lingua locale è sufficiente impostare la cultura inglese nel thread corrente, ripetendo l' operazione su ciascun thread presente nell'applicazione:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
 
namespace UnlocolizeDotNetFrameworkMessage
{
	static class Program
	{
		/// 
		/// The main entry point for the application.
		/// 
		[STAThread]
		static void Main()
		{
 
         		System.Threading.Thread.CurrentThread.CurrentUICulture = 
            			new System.Globalization.CultureInfo("en-US");
 
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new Form1());
		}
	}
}

è poi possibile impostare la cultura del thread corrente ad un valore non soggetto a traduzioni o formattazioni locali:

System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
Come detto in precedenza se vengono creati thread secondari la procedura deve essere ripetuta per ciascuno di essi:
System.Threading.Thread t = new System.Threading.Thread(doSomething);
 
t.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
			
t.Start();

UnlocolizeDotNetFrameworkMessage.zip
		

Blogs Parent Separator My Blog
Author
lupok

My Blog

Tags