by Michael S. Kaplan, published on 2006/05/27 05:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/05/27/608625.aspx
Changing the user interface language really is a rather disruptive operation.
Prior to the multilanguage version of Windows, you would actually have to install a fresh version of Windows based on the desired language. Even once MUI was made available, a change to this per-session setting required logging out and logging back in again.
In Office, changes to the user interface language in the multilanguage version required starting a new session of the Office application in question. Which is truly the application equivalent of that same requirement that the OS has -- starting over to get the update.
Now neither of these cases literally required that firm line from a technical perspective, other than a desire to keep the user experience clean and consistent. And to fully understand the consequences of unclean and inconsistent here, you have to imagine all of the changes like font linking/fallback, mirroring, already loaded string resources, dialog templates, and so on, being mixed in terms of supported languages. The results woul be catastrophic even for Microsoft's own applications, let alone for third parties.
You can think of that line as a sort of "wall of sanity" that keeps the experiences consistent. :-)
So now we come to the .NET Framework....
I swear not a week goes by that the question does not get asked. Here is an example of the question that keeps coming up:
I would like to change the language at runtime. I do not found any topic about that in the documentation. Although restarting the program with a new UIculture change to the according resources by putting:
' Sets the UI culture to French (France)
Thread.CurrentThread.CurrentUICulture = New CultureInfo("fr-FR")
in the "Public Sub New()" procedure as an example, I do not know how we can reset all the strings at the runtime by selecting a menu option to the desired language.
If people look at their VB.Net or C# WinForms code, they see a call to InitializeComponent() in their form constructor that literally builds the form from scratch.
Calling this procdure again is not hard, but it would be pretty unwieldy as a method since it basically recreates every control on the form. At that point, why not just unload and reload the form? You may have a weird experience related to different forms having different languages, but I have to assume you are okay with that or you wouldn't be asking the question, right? :-)
But assuming you wanted to not reset the whole form, the real hard question is how much of a subset can you create, given that a localizer may have resized or moved controls. How much of the InitializeComponent() procedure can you recreate, and how can you keep your custom version in sync with the one that the designer keeps in sync for you?
The distance between the possible and the practical here is substantial; the distance between the possible and the maintainable is orders of magnitude greater still.
How often would it really and truly be worth it?
I know that some people will answer that they agree with this post but their situation is an exception that really requires the functionality, so I will actually pony of up some examples of how to make this sort of thing work if you have to do it. Keep your eyes out for an upcoming post on this soon!
This post brought to you by "჻" (U+10fb, a.k.a. GEORGIAN PARAGRAPH SEPARATOR)
# Rosyna on 27 May 2006 8:38 PM:
# Michael S. Kaplan on 27 May 2006 9:33 PM:
# Rizwan Sharif on 19 Jun 2006 10:25 AM:
# Abhimanyu singh(abhivitmca@gmail.com) on 27 Apr 2009 5:27 PM:
I want to use multlingual application in chat application.so that if user choose any language,corrsponding language will be affected..
for example if user is chatting in English,then if he selects German then all text should be change in German language.
IS it possible in c#.net..plz help me..
# Sol on 4 Nov 2009 11:45 AM:
I use the Thread.CurrentThread.CurrentUICulture but its value (also before the execution) was 'French' although the computer's language was 'English'
PK on 31 Mar 2010 11:57 PM:
we want to give this support to an existing MFC application, how can we do that... can anybody please help me out?
Craig on 9 Apr 2013 10:15 AM:
I find this worked best for me...
dim ci as String = "en-US"
if langSel.text="English" then ci = "en-US"
if langSel.text="Spanish" then ci = "es-ES"
Dim culture_info As New CultureInfo(ci)
Thread.CurrentThread.CurrentUICulture = culture_info
Thread.CurrentThread.CurrentCulture = culture_info
If Me.components IsNot Nothing Then Me.components.Dispose()
Me.Controls.Clear()
Me.InitializeComponent()
FrmMain_Load(Me, New System.EventArgs)