Solved

Multi-Language C#

Posted on 2010-11-11
12
735 Views
Last Modified: 2013-12-17
Hello,

How can i create a button to multi-laguage?

I create a form in pt-BR, en-US and es-ES.
I need to when i click the button language change the form.

Thanks!
0
Comment
Question by:juliodiz
  • 8
  • 4
12 Comments
 
LVL 10

Expert Comment

by:hosneylk
ID: 34118039
0
 

Author Comment

by:juliodiz
ID: 34118050
So i try this one, but inside the groupbox the label doesnt change
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34119149

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);

        }



// calling

            ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));

            resources.ApplyResources(this, "$this");

            RefreshResources(this,resources);

Open in new window

0
 

Author Comment

by:juliodiz
ID: 34120556
Thanks, but the CurrentLocale does not exist in the current context.

How i get the current locale?
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34125152
try using this instead

CultureInfo.CurrentCulture
0
 

Author Comment

by:juliodiz
ID: 34125194
No, nothing change. I click and nothing happens


private void ChangeLanguage(string lang)

        {

            foreach (Control c in this.Controls)

            {

                ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));

                resources.ApplyResources(c, c.Name, new CultureInfo(lang));

            }

        }

        private void RefreshResources(Control ctrl, ComponentResourceManager res)

        {

            ctrl.SuspendLayout();

            res.ApplyResources(ctrl, ctrl.Name, CultureInfo.CurrentCulture);

            foreach (Control control in ctrl.Controls)

                RefreshResources(control, res); // recursion

            ctrl.ResumeLayout(false);

        }

        private void button5_Click(object sender, EventArgs e)

        {

            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));

            resources.ApplyResources(this, "en-US");

            RefreshResources(this, resources);

        }

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:juliodiz
ID: 34125244
This is the correct, sorry
private void RefreshResources(Control ctrl, ComponentResourceManager res)

        {

            ctrl.SuspendLayout();

            res.ApplyResources(ctrl, ctrl.Name, CultureInfo.CurrentCulture);

            foreach (Control control in ctrl.Controls)

                RefreshResources(control, res); // recursion

            ctrl.ResumeLayout(false);

        }

        private void button5_Click(object sender, EventArgs e)

        {

            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));

            resources.ApplyResources(this, "en-US");

            RefreshResources(this, resources);

        }



        private void button4_Click(object sender, EventArgs e)

        {

            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));

            resources.ApplyResources(this, "pt-BR");

            RefreshResources(this, resources);

        }

Open in new window

0
 

Author Comment

by:juliodiz
ID: 34125252
I click and anthing happens, dont change to us-EH,

any idea?
0
 
LVL 10

Accepted Solution

by:
hosneylk earned 500 total points
ID: 34125633
this?
private void ChangeLanguage(string lang)

        {

            ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));

            resources.ApplyResources(this, "$this");

            RefreshResources(this, resources, lang);

        }



        private void RefreshResources(Control ctrl, ComponentResourceManager res, string lang)

        {

            ctrl.SuspendLayout();

            res.ApplyResources(ctrl, ctrl.Name, new CultureInfo(lang));

            foreach (Control control in ctrl.Controls)

                RefreshResources(control, res); // recursion

            ctrl.ResumeLayout(false);

        }



        private void button5_Click(object sender, EventArgs e)

        {

            ChangeLanguage(this, "en-US");

        }



        private void button4_Click(object sender, EventArgs e)

        {

            ChangeLanguage(this, "pt-BR");

        }

Open in new window

0
 

Author Comment

by:juliodiz
ID: 34125726
Ok! Thanks again

But now error in the:

RefreshResources(control, res); = No overload for method RefreshResource
and
ChangeLanguage(this, "en-US"); = No overload for method ChangeLanguage

0
 

Author Comment

by:juliodiz
ID: 34125742
OK!

Now works!

Thank a lot! realy, thanks.

private void ChangeLanguage(string lang)

        {

            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));

            resources.ApplyResources(this, "$this");

            RefreshResources(this, resources, lang);

        }



        private void RefreshResources(Control ctrl, ComponentResourceManager res, string lang)

        {

            ctrl.SuspendLayout();

            res.ApplyResources(ctrl, ctrl.Name, new CultureInfo(lang));

            foreach (Control control in ctrl.Controls)

                RefreshResources(control, res, lang); // recursion

            ctrl.ResumeLayout(false);

        }



        private void button5_Click(object sender, EventArgs e)

        {

            ChangeLanguage("en-US");

        }

Open in new window

0
 

Author Comment

by:juliodiz
ID: 34125745
But, how i can pass this language to the next form?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now