Last post Apr 10, 2011 07:08 PM by 6233114
Apr 10, 2011 12:00 AM|6233114|LINK
I have a drop down list that allows the user to select a language (English, Arabic, Russian, Polish etc).
When the user selects the language from the drop down list, I want to change the language of just one label to the language selected in the drop down list, while leaving the language of the web site unchanged.
I have the relevant resource files installed and I can extract the language code (en-US, ar, ru, pl etc) from the drop down list, but how can I apply this to change the laguage of the label?
I have tried Google, but I can only find how to localize an entire web application and not just a single solitary label.
Apr 10, 2011 04:05 AM|smirnov|LINK
You can try
Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
Select Case DropDownList1.SelectedItem.Value
Case "en-US": Label1.Text = "English text"
Case "ar": Label1.Text = "Arabic text"
Case "ru": Label1.Text = "Russian text"
Hope this helps.
Apr 10, 2011 07:08 PM|6233114|LINK
I managed to figure it out after some blood, sweat and tears.
This is the server side code that actually changes the language of one label on a page without changing the language of the entire website:
I assign the language code programmatically, so languageCode_String would be assigned as ar, fr, pl, en-US, en-GB etc and then use GetGlobalResourceObject and assign it to the label as follows:
CultureInfo culture = new CultureInfo(languageCode_String);
lab1.Text = HttpContext.GetGlobalResourceObject("Resource", "NameDetailsText", culture).ToString();
I hope that this can help some one else.