Click here to Skip to main content
15,939,960 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Does anyone have an idea why my code is not working? I get English strings everywhere.

Note that is not an ASP.NET project but an actual WinForms project.

I have set up a windows forms project to use localization so that it will support Arabic and English languages.

C#
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

       Admin admin = new Admin();
       this.Close();
       admin.Show();

Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-KW");

       Admin admin = new Admin();
       this.Close();
       admin.Show();


What I have tried:

C#
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
       this.Controls.Clear();
       this.RightToLeftLayout = false;
       InitializeComponent();
       Properties.Settings.Default["lang"] = "en-US";
       Properties.Settings.Default.Save();

           Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-KW");
       this.Controls.Clear();
       InitializeComponent();
       Properties.Settings.Default["lang"] = "ar-KW";
       Properties.Settings.Default.Save();


and

C#
var ChangLanuguage = new Changelanguage();
           ChangLanuguage.Updateconfig("language", "ar-KW");
           Application.Restart();


C#
private void ChangeLanguage(string lang)
        {
            foreach (Control c in this.Controls)
            {
                ComponentResourceManager resources = new ComponentResourceManager(typeof(Admin));
                resources.ApplyResources(c, c.Name, new CultureInfo(lang));
            }
        }



and

C#
private void metroTile58_Click(object sender, EventArgs e)
       {
           switch(Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
           {
               case "ar-KW":Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");break;

               case "en-US": Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-KW"); break;
           }
           this.Controls.Clear();
           InitializeComponent();
       }


It works when I test it by starting to debug but when I setup (When the program is extracted) the application it stops working.
Posted
Updated 16-Apr-19 21:31pm
v2

1 solution

Winforms creates resource files for various languages you have changed your forms design for (changed the strings and layout etc.).

If your application works in debug mode and you can switch languages, then check the "bin\debug" folder and copy/deploy the language folder "ar" or "ar-KW" along with your EXE file on other machines
 
Share this answer
 
Comments
el_tot93 17-Apr-19 3:41am    
how can i do that
Mehdi Gholam 17-Apr-19 3:43am    
What part of my answer is not clear?
el_tot93 17-Apr-19 4:02am    
the second
Mehdi Gholam 17-Apr-19 4:29am    
Go to your debug folder and copy everything including all folders (except the .pdb) files to your target machine.
el_tot93 17-Apr-19 4:34am    
thx it work with me :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900