0

I am developing an application in c#. The current language of my system is French. What i want is when i open my application the language should be changed to English. Is there anyway by which i can perform this task. I tried to change the language through code but nothing seems to work.

Here is my code

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Liath
  • 9,913
  • 9
  • 51
  • 81
Fazil Mir
  • 783
  • 2
  • 9
  • 23
  • Exactly what do you mean "nothing seems to work"? What did you want to have happen? What actually _did_ happen? – John Saunders Jan 30 '14 at 13:21
  • The current language of my system is French. What I want When I open my application the language should be changed to English. @JohnSaunders – Fazil Mir Jan 30 '14 at 13:24
  • What do you mean "the language should be changed to English"? Do you mean, for instance, that you have a label that says "Bonjour", and you need it to say "Good morning"? – John Saunders Jan 30 '14 at 13:27
  • No bro. Look i developed an application. But when i deployed it on clients machine the functionality was not working properly but it was working fine on my own system as i was having English language as my current language. but my client is from netherland so the language on his system is dutch. here is my code which is affecting `Convert.ToDouble(value);` its working fine when the language is english but when the language is changed i dont get the proper value. – Fazil Mir Jan 30 '14 at 13:31
  • @FazilMir , instead of changing the culture, I would suggest to use the user culture to convert. Better use `double.TryParse(value, userculture, NumberStyles.Any, out result)` – Junaith Jan 30 '14 at 13:45
  • @Junaith i have used `Convert.ToDouble(value);` in my app more than 30 times. I dont want to change it now. anyways thanx – Fazil Mir Jan 30 '14 at 14:08
  • @FazilMir Dig through my answers. I have few explaining the system how to achieve on-fly language change. Start here http://stackoverflow.com/a/21286999/1704458 – T.S. Jan 30 '14 at 14:34

4 Answers4

3

I'm going to assume that you have your forms localized to both French and English. If that is the case, then once you run the code in your question, new forms you display will show in the new language.

If you want to change the language and have forms that are currently being shown redisplay their text in the new language, you have to put together something that responds to the culture being changed and update all the labels, radio buttons, and so on.

Fortunately, someone has already done this work for you:

http://www.codeproject.com/Articles/23694/Changing-Your-Application-User-Interface-Culture-O

prprcupofcoffee
  • 2,950
  • 16
  • 20
1

Windows will not automatically translate your application, you need to provide these yourself and load them into language specific.

This article explains the process quite well. You're updating the culture which tells the system which resource files to use. Now you need to provide the text to show.

Liath
  • 9,913
  • 9
  • 51
  • 81
0

You have to reload forms (or switch language before you create any form)

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
Form1 form1 = new Form1();
form1.ShowDialog();

This assume, you are using satellite assemblies and already have form translated.

If you want to change keyboard layout (FR -> EN), then, while it is also possible, you better don't. As user may have his preference for which layout he want to use by default.

Sinatr
  • 20,892
  • 15
  • 90
  • 319
0

I can't replicate your problem here. The code should work fine in term of changing the way Double.Parse method works. Here is how I did the test :

string duit = "1.000.100";  //this is a valid number format in my current culture
string money = "1,000,100"; //but this is not valid
var culture = CultureInfo.CurrentCulture; //my current culture is indonesia (id-ID)
var duitDouble = double.Parse(duit);  //parsed successfully
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
culture = CultureInfo.CurrentCulture;  //now current culture is english (en-US)
var moneyDouble = double.Parse(money); //parsed successfully

Besides, I really suggest to rephrase your question and title to avoid misunderstanding. That will be good for you and people that intend to help. As you can see, most of the answers posted are not actually answering the question (the actual problem is indicated in OP's second comment in the question).

har07
  • 88,338
  • 12
  • 84
  • 137