locked
Change the Language of only one Label in a form RRS feed

  • Question

  • User807891885 posted

    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.

    Essentially, I just want to localize one label on my form using javascript  for client side use and C# for server side use.

    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. 

    Sunday, April 10, 2011 12:00 AM

Answers

  • User807891885 posted

    Thanks smirnov,

    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.

    Now, to write the javascript version of the above code for the client side version and I am finished.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 10, 2011 7:08 PM

All replies

  • User1508394307 posted

    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"
    ...
    End Select
    
    End Sub	

    Hope this helps.

    Sunday, April 10, 2011 4:05 AM
  • User807891885 posted

    Thanks smirnov,

    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.

    Now, to write the javascript version of the above code for the client side version and I am finished.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 10, 2011 7:08 PM