Friday, March 23, 2007

Creating And Using Satellite Assembly!!!!

As a professional developer, your clients might ask you to develop a website in which users can choose the language they want the site to be in. Somehow, this scenario can be done by developing several pages with several languages. Finally, you can satisfy the clients' requirements. However, it takes you a very long time, and it also wastes your money. There is a faster way to accomplish the requirement. Let's enjoy!
Satellite Assemblies are the answer to this problem!!!!!
I'll tell you what i've experienced while creating a satellite assem
bly...let's try one windows application
1)now create one project naming windowsapplication1

2)now in the windows form add one lable and one dropdown
3)add item and there values in the drop down (english,en-GB) (Swiss German,de-CH) etc.
4)now go to add new resource files with names (any name you like) eg resource1.resx ,string.resx
5) now the way you have to create these resource file is very important here,for example you are choosing a file name as resource1.resx then the files youo will create will be as follows: resource1.resx,resource1.en-GB.resx,resource1.de-CH,resou
rce1.de-AT (I'm using resources for three languages here).
6)open each resource file and set some strings for each file.like the below one for each language and the default language also.













7)Now that you have specified all the resource now you have to build the code to generate all the dll's.
8)Now write the code to use these resource file in your windows form...I've give just a simple funtionality that whenever you change the selection from the dropdown then it will change the text of the lable according to the language selected.

so here is the code in C# for the windows form:
using System;
using System.Collections.Generic;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Globalization;
using System.Threading;


namespace WindowsApplication1
{
public partial class Form1 : Form
{

private ResourceManager rm;
public Form1()
{
InitializeComponent();
}


private void Form1_Load(object sender, EventArgs e)
{

rm = new ResourceManager("WindowsApplication1.Resource1",typeof(Resource1).Assembly);
//string resource = rm.GetString("String1");


//MessageBox.Show(resource);


}

private void ultraComboEditor1_ValueChanged(object sender, EventArgs e)
{
string slang = ultraComboEditor1.Value.ToString();

Thread.CurrentThread.CurrentUICulture = new CultureInfo(slang);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(slang);

label1.Text = rm.GetString("String1");

}
}

}
Now try changing the selection and you will see that the lable text will also change.
see the below scenario and you will get why these satellite assemblies are really important: