13

I am developing a multilingual program in C# on Windows

How to change Windows writing language on certain actions...
e.g. to change from English to Arabic on focus event.

Thanks

Betamoo
  • 14,964
  • 25
  • 75
  • 109
  • These similar post may shed some light http://stackoverflow.com/questions/397356/develop-multilingual-windows-application-c http://stackoverflow.com/questions/270829/internationalizing-desktop-app-within-a-couple-years-what-should-we-do-now Cheers! – Sandeep Kumar M Jul 19 '10 at 08:34

5 Answers5

16

To select a whole new culture, set the CurrentThread.CurrentCulture to a new culture, e.g. to set to French:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("fr-FR");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;

You can find a list of the predefined CultureInfo names here and here.

If you want to change certain aspects of the default culture, you can grab the current thread's culture, use it it's name to create a new CultureInfo instance and set the thread's new culture with some changes, e.g. to change the current culture to use the 'Euro' symbol:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo( System.Threading.Thread.CurrentThread.CurrentCulture.Name);
ci.NumberFormat.CurrencySymbol = "€";
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
barlop
  • 12,887
  • 8
  • 80
  • 109
Dr Herbie
  • 3,930
  • 1
  • 25
  • 28
  • 3
    For some situations it is also necessary to set System.Threading.Thread.CurrentThread.CurrentUICulture. (Note the "UI" in the middle of the property name.) – RenniePet Aug 19 '15 at 03:40
  • I had to set the UICulture also while running unit tests. Comment above saved me :) – jpgrassi Nov 25 '18 at 19:12
3

In load Event insert the code below:

InputLanguage.CurrentInputLanguage =
      InputLanguage.FromCulture(new System.Globalization.CultureInfo("fa-IR"));
Miss.Alpha
  • 142
  • 1
  • 2
  • 11
ali
  • 185
  • 1
  • 3
3
Thread.CurrentThread.CurrentCulture = yournewculture;

Also see the CurrentUICulture property.

leppie
  • 115,091
  • 17
  • 196
  • 297
2

In addition, if you want to refresh all the controls' resources at runtime, you will need to use something like this:

private void RefreshResources(Control ctrl, ComponentResourceManager res)
{
    ctrl.SuspendLayout();
    res.ApplyResources(ctrl, ctrl.Name, CurrentLocale);
    foreach (Control control in ctrl.Controls)
        RefreshResources(control, res); // recursion
    ctrl.ResumeLayout(false);
}

If you want a better example check my blog.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
FvZ
  • 45
  • 6
2

This statements were helpful for me:

string myLanguage = "HE-IL";
InputLanguage.CurrentInputLanguage =
   InputLanguage.FromCulture(new System.Globalization.CultureInfo(myLanguage));
barlop
  • 12,887
  • 8
  • 80
  • 109
Nir Tsabar
  • 69
  • 1
  • 2
  • this is great too, amending that first line, can do it for whatever country http://www.lingoes.net/en/translator/langcode.htm – barlop Mar 18 '16 at 14:53