Calling SatelliteAssembly in C#.NET
-
Hi, I have created two different satellite assemblies corresponding to two languages specific resource files -english and french.I am calling these assemblies on the basis of the language selected from the combobox and changing the label text.Please refer to the code below:- private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { try { ResourceManager rm = null; if (comboBox1.Text == "English") { rm = new ResourceManager("Satellite.en-US", Assembly.GetExecutingAssembly()); label1.Text = rm.GetString("String1"); } else if (comboBox1.Text == "French") { rm = new ResourceManager("Satellite.fr-FR", Assembly.GetExecutingAssembly()); label1.Text = rm.GetString("String1"); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } } The above code works fine and the label text is getting changed according the language selected.But I don't want to do this: rm = new ResourceManager("Satellite.en-US", Assembly.GetExecutingAssembly()); I want, .NET to detect the current culture of the system and refer the required dll.If the current culture is french then .NET should refer the french dll automatically.Is there any way to do this task.Actually in future if any new language is added then there is no need to add anything in the code.
-
Hi, I have created two different satellite assemblies corresponding to two languages specific resource files -english and french.I am calling these assemblies on the basis of the language selected from the combobox and changing the label text.Please refer to the code below:- private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { try { ResourceManager rm = null; if (comboBox1.Text == "English") { rm = new ResourceManager("Satellite.en-US", Assembly.GetExecutingAssembly()); label1.Text = rm.GetString("String1"); } else if (comboBox1.Text == "French") { rm = new ResourceManager("Satellite.fr-FR", Assembly.GetExecutingAssembly()); label1.Text = rm.GetString("String1"); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } } The above code works fine and the label text is getting changed according the language selected.But I don't want to do this: rm = new ResourceManager("Satellite.en-US", Assembly.GetExecutingAssembly()); I want, .NET to detect the current culture of the system and refer the required dll.If the current culture is french then .NET should refer the french dll automatically.Is there any way to do this task.Actually in future if any new language is added then there is no need to add anything in the code.
You can to that.
ResourceManager rm = new ResourceManager( "Satellite"+System.Globalization.CultureInfo.CurrentCulture.Name, Assembly.GetExecutingAssembly() );
NassosGanDad
-
You can to that.
ResourceManager rm = new ResourceManager( "Satellite"+System.Globalization.CultureInfo.CurrentCulture.Name, Assembly.GetExecutingAssembly() );
NassosGanDad
Thanks for your reply.Now i need to assigned ResourceManager instance only once.
modified on Wednesday, December 05, 2007 5:26:42 AM
-
Thanks for your reply.Now i need to assigned ResourceManager instance only once.
modified on Wednesday, December 05, 2007 5:26:42 AM
Going little ahead with the same topic(Satellite assembly),i have to upgrade my code. I have initialize resource manager as:- ResourceManager rm = new ResourceManager("Satellite." + System.Globalization.CultureInfo.CurrentCulture.Name, Assembly.GetExecutingAssembly()); From the above code the application automatically detects the current culture of the system.Depending on the current culture I am setting the labels text on a form like this:- private void button1_Click(object sender, EventArgs e) { SetText(this); } void SetText(Control ctl) { string text = rm.GetString(ctl.Name); if (text != null) ctl.Text = text; foreach (Control ctl1 in ctl.Controls) { SetText(ctl1); } } I am trying to find out a way by which my application set the Labels text itself when ever the system language changes. I mean i want to get rid of SetText() method written above.Is there any way by which I don't have to write any method like SetText() for setting all my controls text.If you have any idea then please let me know. Thanks.