locked
Creating a multilingual app in C# RRS feed

  • General discussion

  • My application is made only in English and i want to switch it to multilingual version . But instead of user changing default language in regionaal settings i gave my application a "ToolStripMenuItem" called langauge and added a submenu for Arabic , Korean and English version . 

    As far i am aware three things are required -:

    1. Writing a code in click event of that Langauage subemenu say "Arabic" 
    2. Creating a corresponding resx file 
    3. Also i had set the Form localizable property to "True"

    This is the code i added to my Program in Form1()

        //this variable indicates the current language in use
            CultureInfo CurrentLocale;
            
            public Form1()
            {
                InitializeComponent();
                valueInit();
                //MessageBox.Show(rfidCard.PORT + "");
            }


            //Lets start adding the multilingual code here


            

            //change the language in real time 
            private void ChangeLanguage(string lang)
            {
                CurrentLocale = new CultureInfo(lang);
                foreach (Control c in this.Controls)
                {
                    ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
                    resources.ApplyResources(c, "$this");
                    RefreshResources(this, resources);
                }
            }

            //refresh all the controls e sub-controls of the form 
            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);
            }

            private void englishToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ChangeLanguage("en-US");
            }

            private void arabicToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ChangeLanguage("ar-SA");
            }

            private void koreanToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ChangeLanguage("ko-KR");
            }

            // the code ends here

    Second i added a resx file called Form1.ar-SA.resx and inside that just for testing added two things :

    $this.Text = Abc M البرمجيات تطبيق ويب
    >>$this.Name = Form1

    However when i run my application and try clicking on language Arabic it still does not change anything . 

    can someone please help me to find where i went wrong or what am i missing ?

    Also in the default.resx i found another column saying
    >>$this.Type = System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    Does that make any difference ?

    EDIT1 : While browsing i found i also need to have  genaerated a designer.cs file cprresponding to it . The search engines talked about having some "RazorGenerator" installed  . I tried installing it from the package manager but it failed . Any light on this please 
    Wednesday, May 14, 2014 3:54 AM