473,508 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing Localization on the fly

I've got a windows forms application that uses french and english. We're
localizing it right now. It does appear to work if I set the language

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");

Just before we run it.

How can I setup a button that will toggle the language while the program is
running? It seems once it's running, changing the language has no effect.

Thanks,
Greg
Nov 3 '08 #1
6 13179
"greg" <th*****@nospam.nospamwrote in message
news:53**********************************@microsof t.com...
I've got a windows forms application that uses french and english. We're
localizing it right now. It does appear to work if I set the language

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");

Just before we run it.

How can I setup a button that will toggle the language while the program
is
running? It seems once it's running, changing the language has no effect.
The language is processed in the Constructor of the Form. So once a form
is already constructed, it won't change language. After you change the
Thread.CurrentThread.CurrentUICulture, new forms that you open will show in
the new language, but the form itself from which you executed that change,
as well as any previously opened forms, will not change. You can close and
reopen the current form if you want it to show in the new language.

Nov 3 '08 #2
Localization data(strings and other data if any) are stored in satellite
dlls. So, once a dll is loaded, you can't unload that dll and load
another dll. The only way to change that (as far as I know) is to
restart your application. It applies to both .Net applications and MFC
applications.

Thanks & Regards,
Ashutosh

greg wrote:
I've got a windows forms application that uses french and english. We're
localizing it right now. It does appear to work if I set the language

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");

Just before we run it.

How can I setup a button that will toggle the language while the program is
running? It seems once it's running, changing the language has no effect.

Thanks,
Greg
Nov 3 '08 #3
Hi Greg,

you can change it, look how it's done in
Windows Form Designer generated code.

Basically it's working like this:
private void localize(CultureInfo culture)
{
Thread.CurrentThread.CurrentUICulture = culture;

foreach (Form form in Application.OpenForms)
ApplyControlResources(new
ComponentResourceManager(form.GetType()), form);
}

private void ApplyControlResources
(ComponentResourceManager resourceManager, Control control)
{
if (control is Form)
resourceManager.ApplyResources(control, "$this");
else
resourceManager.ApplyResources(control, control.Name);

if (control is IContainerControl)
{
foreach (Control childControl in control.Controls)
{
ApplyControlResources(resourceManager, childControl);
}
}
}

Additional, you have to iterate through each forms menus and do the same.

Walter
Nov 4 '08 #4
Hi Greg,

Walter has provided a great solution to this question.

This solution works because the ComponentResourceManager.ApplyResources
will load the resource dll at runtime. It will not impact the performance
because the loading will only happen in the first time to apply the
resource and later the resource dll will stay in memory.

Please try Walter's solution and let us know if you have any problem when
implementing it. Thanks.

Regards,
Hongye Sun (ho*****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 4 '08 #5
On Nov 4, 2:43*am, greg <thef...@nospam.nospamwrote:
I've got a windows forms application that uses french and english. We're
localizing it right now. It does appear to work if I set the language

* Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
* Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");

Just before we run it.

How can I setup a button that will toggle the language while the program is
running? It seems once it's running, changing the language has no effect.
Have a look at the following article on code project:

http://www.codeproject.com/KB/cs/CultureManager.aspx

It provides a component that allows you to change the active culture
of all forms/controls in your application.

Regards
Grant Frisken
Infralution

Infralution Globalizer.NET - localization made easy
www.infralution.com/globalizer.html
Nov 4 '08 #6
Hi Greg,

I have not heard from you for several days. I am writing to check the staus
of this issue. Would you mind letting us know any progress from your side?
If you have any problem regarding this issue, please feel free to let us
know. It is our pleasure to help you. Thanks.

Have a nice day.

Regards,
Hongye Sun (ho*****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.
*
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 14 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1571
by: Sebastian Bargmann | last post by:
Hi, I think I've read everything there is to read about localization in dotNET and I still don't get it. I understand the concepts and I understand the code, but there's no way that the...
2
1920
by: Kallis | last post by:
Hello, I have the following situation when trying to localize my software: I have BIG solution with about 80 projects. In one of the projects I have a number of dialogs (the dialog project :-)...
4
2973
by: Weinand Daniel | last post by:
i'd like to monitor changes of the "Control.Name" porperty during designtime. if the user changes the name in designer my event musst fire. i have created a own button control. with an event...
1
2690
by: enahar | last post by:
Dear Sir/Madam We are going to do the Localization/Globalisation for our product which has nearly got 284 forms using satellite Assemblies. I have got 2 questions 1. How to handle Substrings....
4
1188
by: Matthias S. | last post by:
Hi everybody, I'm starting to design a Portal-Style application which should support a couple of languages. What I figured is that one could use various resx files to localize more or less...
8
3708
by: Henry | last post by:
Hi, in a Windows form VB.Net project I use localization for all texts. In App.Config I added: <appSettings> <add key="locale" value="de"/> </appSettings> In the project I have ressource...
5
2393
by: archana | last post by:
Hi all, I am having confusion regarding localization in .net. I have one form on which i have some labels and button. After designing that form what i did is set localization property of form...
2
1144
by: Robert Dufour | last post by:
In an english only application, it is fairly easy to make the table and field names in your application descriptive so that on creating the interface, most tools that bind data take the default...
2
2577
by: Chris Walls | last post by:
We have created two (2) global resource files in App_GlobalResouces: Global.resx Global.es-MX.resx In an ASP.NET page, we use two different syntaxes to set text on the page, depending upon the...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.