Understanding Globalization: Globalization is process of identifying all the localizable resources in the application, that will support multiple cultures. Ideally it is perform during design phase of an application, so that the resources always remains separate from the code.
Understanding Localization: In Localization you customize the application for new locales. This consist of translating resources that you identified during the globalization phase.
Difference between Localization and Globalization: Globalization is process of identifying how many resources needs to be localized to adopt a multiple culture support, while Localization is actual process of translating resource to a specific culture.
Understanding concept with Example
Step1: Create a Web Project.
Step2: Design your form.
For this example : Take 4 label controls, 4 textbox controls and 1 drop-down list control.
Place the control on form as shown in figure.
Step3: Identifying Resources that needs to be localized (Globalization Phase).
We want the output as shown in figure:
So here Resource that needs localization are
Language Name Label
Long Date Label
currency Label
Amount Label
Now, Applying Localization to resources which needs to be localized and globalization phase. (Localization Phase begin).
Step5: Creating Resource File.
For this example i am creating resource file for French and German culture and other culture would get value from default resource file. Right click the Project in Solution Explorer and add a folder and name it. here i have named it to "MyLocalResources" you can name accordingly.
Now, Right click the Project in Solution Explorer and add a Resource File and add the content as shown in figure.
Creating Default Resource File "MyRes.resx"
(content of this resource file would be applied to resource in case resource content for language selected by user is not available.)
Creating French Resource File
Creating German Resource File
Step6: Adding code in .CS file to make it work
Adding Namespace
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Reflection;
Understanding Localization: In Localization you customize the application for new locales. This consist of translating resources that you identified during the globalization phase.
Difference between Localization and Globalization: Globalization is process of identifying how many resources needs to be localized to adopt a multiple culture support, while Localization is actual process of translating resource to a specific culture.
Understanding concept with Example
Step1: Create a Web Project.
Step2: Design your form.
For this example : Take 4 label controls, 4 textbox controls and 1 drop-down list control.
Place the control on form as shown in figure.
Step3: Identifying Resources that needs to be localized (Globalization Phase).
We want the output as shown in figure:
So here Resource that needs localization are
Language Name Label
Long Date Label
currency Label
Amount Label
Now, Applying Localization to resources which needs to be localized and globalization phase. (Localization Phase begin).
Step5: Creating Resource File.
For this example i am creating resource file for French and German culture and other culture would get value from default resource file. Right click the Project in Solution Explorer and add a folder and name it. here i have named it to "MyLocalResources" you can name accordingly.
Now, Right click the Project in Solution Explorer and add a Resource File and add the content as shown in figure.
Creating Default Resource File "MyRes.resx"
(content of this resource file would be applied to resource in case resource content for language selected by user is not available.)
Creating French Resource File
Creating German Resource File
Step6: Adding code in .CS file to make it work
Adding Namespace
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Reflection;
Filling Dropdown with set of languages for user-choice.
Code in Page Load Event.
if(!Page.IsPostBack)
{
//CultureInfo Class GetCultures gives collection of language.
foreach(CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
//Filling the language collection into drop-downlistbox for user choice.
ddlLanguage.Items.Add(new ListItem(ci.EnglishName,ci.Name));
}
//Calling the Event when page loads for the first time.
ddlLanguage_SelectedIndexChanged(sender,e);
}
Assigning selected language value to current thread, to reflect changes.
private void ddlLanguage_SelectedIndexChanged(object sender, System.EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLanguage.SelectedValue);
Thread.CurrentThread.CurrentCulture = new CultureInfo(ddlLanguage.SelectedValue);
//Applying Localization
ApplyLocalization();
ApplyUILocalization();
}
private void ddlLanguage_SelectedIndexChanged(object sender, System.EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLanguage.SelectedValue);
Thread.CurrentThread.CurrentCulture = new CultureInfo(ddlLanguage.SelectedValue);
//Applying Localization
ApplyLocalization();
ApplyUILocalization();
}
Code which requires localization value.
private void ApplyUILocalization()
{
ResourceManager rm = new ResourceManager("LocalizationPrac6.MyLocalResources.myRes",Assembly.GetExecutingAssembly(),null);
if(rm != null)
{
lblLanguageName.Text = rm.GetString("webform1.lblLanguageName");
lblLongDate.Text = rm.GetString("webform1.lblLongDate");
lblCurrency.Text = rm.GetString("webform1.lblCurrency");
lblAmount.Text = rm.GetString("webform1.lblAmount");
}
}
private void ApplyUILocalization()
{
ResourceManager rm = new ResourceManager("LocalizationPrac6.MyLocalResources.myRes",Assembly.GetExecutingAssembly(),null);
if(rm != null)
{
lblLanguageName.Text = rm.GetString("webform1.lblLanguageName");
lblLongDate.Text = rm.GetString("webform1.lblLongDate");
lblCurrency.Text = rm.GetString("webform1.lblCurrency");
lblAmount.Text = rm.GetString("webform1.lblAmount");
}
}
Code which does not requires localization.
private void ApplyLocalization()
{
//Lets Assume currency and amount to keep example simple.
double dblCurrency = 500.50;
double dblAmount = 9580000.75;
//No extra effort for localization as you see here.
txtLangName.Text = ddlLanguage.SelectedItem.Text;
txtLongDate.Text = DateTime.Now.ToLongDateString();
txtCurrency.Text = dblCurrency.ToString("c");
txtAmount.Text = dblAmount.ToString("n");
}
Now, run the application and select the different culture and based on selection you will get the localized display as shown in figure:
When associated resource file not available culture from Default Resource File would be shown.
private void ApplyLocalization()
{
//Lets Assume currency and amount to keep example simple.
double dblCurrency = 500.50;
double dblAmount = 9580000.75;
//No extra effort for localization as you see here.
txtLangName.Text = ddlLanguage.SelectedItem.Text;
txtLongDate.Text = DateTime.Now.ToLongDateString();
txtCurrency.Text = dblCurrency.ToString("c");
txtAmount.Text = dblAmount.ToString("n");
}
Now, run the application and select the different culture and based on selection you will get the localized display as shown in figure:
When associated resource file not available culture from Default Resource File would be shown.
Selecting German Culture
5 comments:
Not working It shows following error :
System.Resources.MissingManifestResourceException was unhandled by user code
Message="Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"LocalizationPrac6.MyLocalResources.myRes.resources\" was correctly embedded or linked into assembly \"App_Web_lw5x6rb-\" at compile time, or that all the satellite assemblies required are loadable and fully signed."
Source="mscorlib"
StackTrace:
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
at System.Resources.ResourceManager.GetString(String name)
at _Default.ApplyUILocalization() in d:\SAMPLES\Glb\WebForm1.aspx.cs:line 58
at _Default.ddlLanguage_SelectedIndexChanged(Object sender, EventArgs e) in d:\SAMPLES\Glb\WebForm1.aspx.cs:line 50
at _Default.Page_Load(Object sender, EventArgs e) in d:\SAMPLES\Glb\WebForm1.aspx.cs:line 29
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
you are passing wrong values to resource manager constructor.
It should be
ProjectName - LocalizationPrac6
FolderName - MyLocalResources
Resource FileName - myRes (Note: No extension)
It is obviouse that you have different value, and thtz the reason why you are getting the error.
ResourceManager rm = new ResourceManager("LocalizationPrac6.MyLocalResources.myRes",Assembly.GetExecutingAssembly(),null);
Even thouh i passed the correct value i am getting the same error, unable to fix this issue, saw similar kind of issue in several posts in 2005 and 2008?? Any idea pls suggest.
my code is:
---------------
ResourceManager rm = new ResourceManager("Refresh.MyLocalResources.MyRes", System.Reflection.Assembly.GetExecutingAssembly(), null);
Refresh - Is my application name
MyLocalResources - Folder name
MyRes - ResourceFile name
Even thouh i passed the correct value i am getting the same error, unable to fix this issue, saw similar kind of issue in several posts in 2005 and 2008?? Any idea pls suggest.
my code is:
---------------
ResourceManager rm = new ResourceManager("Refresh.MyLocalResources.MyRes", System.Reflection.Assembly.GetExecutingAssembly(), null);
Refresh - Is my application name
MyLocalResources - Folder name
MyRes - ResourceFile name
Rahul,, :::
I am getting the following error,,
please suggest solution......
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "globals.resources" was correctly embedded or linked into assembly "App_Web_kmbh8jcd" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Post a Comment