Multilanguage support on string?

Last post 01-19-2009 12:54 PM by jawahars. 10 replies.

Sort Posts:

  • Multilanguage support on string?

    01-10-2009, 7:04 AM
    • Member
      62 point Member
    • talsja
    • Member since 07-10-2006, 8:54 PM
    • Netherlands
    • Posts 31

     Hello,

     I am developing an webapplication (3.5 C#) and the requirements are language support for 4 languages.

    Now i have the following question.

    In some cases i set the text for a label in C# code behind.

    asp.net:

     <asp:Label id="Label1" runat="server" text="" />

     C# :

    try

    {

     Label1.Text = "Here is my message for label1";

    }

    Now the question is how do i localize this Label?

    Thanx in advance

     

     

     

     

  • Re: Multilanguage support on string?

    01-10-2009, 7:57 AM
    • All-Star
      122,336 point All-Star
    • XIII
    • Member since 07-01-2002, 3:59 AM
    • Essen, Belgium
    • Posts 13,570
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
  • Re: Multilanguage support on string?

    01-10-2009, 11:18 AM
    • Member
      62 point Member
    • talsja
    • Member since 07-10-2006, 8:54 PM
    • Netherlands
    • Posts 31

     Hi Kris,

     

    Thanx for your replay. I know how to work with globalisation and multilanguage support.

    I have already imported it. The only thing is when the label's text is set in code behind its resource will not be set.

     

    So in code i have:

    this.Label2.Text = "This is my test text";

    In asp.net i have:

    <asp:Label ID="Label2" runat="server" Text="<%$ Resources:Strings, Label2 %>"></asp:Label>

    My Global resource file is in 4 languages. So in dutch the text for label2 would be: Dit is mijn test text.

    So now when i choose a language in my application. Say Dutch. All my labels are displaying dutch text except the labels where the text is written in de code.

    So i don't understand why my resource file is not applyed.

    It looks like code is overrulling my strings, Label2

    Any idea?

  • Re: Multilanguage support on string?

    01-10-2009, 12:53 PM
    Answer
    • All-Star
      122,336 point All-Star
    • XIII
    • Member since 07-01-2002, 3:59 AM
    • Essen, Belgium
    • Posts 13,570
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Hi,

    talsja:
    All my labels are displaying dutch text except the labels where the text is written in de code.

    So the code in your codebehind's not working?

    If so you can do it with Label2.Text = GetGlobalResourceObject("CommonLabels", "TestMe").ToString();

    Where CommonLabels is the name of the .resx file in the App_GlobalResources and TestMe is the name of 1 entry in that resx.

    Grz, Kris.

  • Re: Multilanguage support on string?

    01-14-2009, 7:00 PM
    • Member
      62 point Member
    • talsja
    • Member since 07-10-2006, 8:54 PM
    • Netherlands
    • Posts 31

     Okay, but what about this:

    Case:

    Label1.Text = ""/>

    Code:

    When error is true:

    Label1.Text = "Dear" + currentUser + "This is not true";

    When error is not true:

    Label1.Text = "Dear" + currentUser + "This is so false";

    Now you see that the label1.Text is dynamic and depends on some conditions.

    Now offcourse i can set GlobalResources but then i have to make 2 labels. Label1 in case of error true and Label2 in case of error true.

    Then i have to set the visability of the labels to false. And set them to true in case the label has to be shown.

    So you see. This is a lot of extra work i can't believe that this is the way to do it. There must be a more logical manner  toch?

     

    Thanx Talsja

     

     

     

  • Re: Multilanguage support on string?

    01-16-2009, 2:03 AM
    • Member
      74 point Member
    • jawahars
    • Member since 04-28-2008, 10:27 AM
    • Chennai,Tamilnadu,India
    • Posts 57

    Hi,

    try this...

    let consider if condition is true the label have to show text1 in label1 and if condition is false then the label have to show the text text2 in label1 from the same resource file (same language and different text). Right

    follow these steps:

    i think u already have  resx files?

    consider:

    first resx file 

    NAME                       VALUE

    truevalue                   text1

    second resx file

    falsevalue                 text2

    store that text in corresponding .resx file in name-value pair

    now move to code behind:

    add the code

    imports system.reflection 

     

    Dim str As New ResourceManager("file name", Assembly.GetExecutingAssembly)

    note: filename without extension(if filename.aspx then here give filename only)

     logic;

    if (true)

    Label1.Text = Me.GetLocalResourceObject("truevalue")

    else if (false)

    Label1.Text = Me.GetLocalResourceObject("falsevalue")

    All the best.. if u have question or not understand reply me. i will try to describe it.

     

    -- "Mark As Answer" if my reply helped you --
    Thanks,
    Jawahar
    Lets screw the Technolgies.
  • Re: Multilanguage support on string?

    01-17-2009, 5:41 PM
    • Member
      62 point Member
    • talsja
    • Member since 07-10-2006, 8:54 PM
    • Netherlands
    • Posts 31

     Dear jawahars,

     Thanx for your reply,

     I understand what u are saying and trying to do. Now it's only possitble to add 1 meta:resourcekey=" tag.

    so in asp.net it will be:

    <asp:Label id="Label1" runat="server" meta:resourcekey ="label1Resource1" />

    So in the lets say strings.en-US.resx file i would have something like this:

    label1Resource1.Text | value =" My label was true so this is my true text value"

    Now it's not clear to me how to set another LabelResource1.Test | value = "My label was false so this is my false text value "

    Maybe you can explain this one to me?

     

    Another question is how to deal with dynamic strings.

    case like this one:

    string currentUser = HttpContext.Current.User.Identity.Name;

    So in code behind i build a string let's say label1.Text = "Hello"  + currentUser + "Nice to have you here!";

    You see that i can't put this string as a global or local string because i don't know in atvance which user im dealing with.

    It would be nice if there's a way to dynamically build the resouce strings.

     

    Im exciting to hear from you

    Thanx in advance

    Talsja

  • Re: Multilanguage support on string?

    01-17-2009, 6:03 PM
    • Member
      62 point Member
    • talsja
    • Member since 07-10-2006, 8:54 PM
    • Netherlands
    • Posts 31

     Okey jawahars,

     Now i dit it like this:

    I have a Globar Resource calles Strings.

    In code behind i use :

    lblError.Text = (String)GetGlobalResourceObject("Strings", "AgendaSaveItemsError");

    in another case i also set some text 

    lblError.Text = (String)GetGlobalResourceObject("Strings", "AgendaFilterItemsError");


    This one works fine!

    The only question left is how to deal with the variable strings like  i discribed earlier

    Thanx in advance

  • Re: Multilanguage support on string?

    01-19-2009, 4:14 AM
    • Member
      74 point Member
    • jawahars
    • Member since 04-28-2008, 10:27 AM
    • Chennai,Tamilnadu,India
    • Posts 57

     Dear talsja,

         Working with dynamic string in localisation is simple.
         first of all forgot the meta:resourcekey attribute, this is only for static text.
         For dynamic text, we can create two name-value pair.
         It is not a rule to create the value only to the element attributes, we can create our own name-value pair.
          EG: the following is the structure of .resx file
          Name             Value
          lblTest.text     corresponding text(this is for static text, whenever the page load it will display in the label)
          truevalue        true text
          falsevalue       false text

       in code behing:
         if (true)
           {
             lblTest.text = Me.GetLocalResourceObject("truevalue")
              }
         else
           {
             lblTest.text = Me.GetLocalResourceObject("falsevalue")
              }

    -- "Mark As Answer" if my reply helped you --
    Thanks,
    Jawahar
    Lets screw the Technolgies.
  • Re: Multilanguage support on string?

    01-19-2009, 8:28 AM
    • Member
      62 point Member
    • talsja
    • Member since 07-10-2006, 8:54 PM
    • Netherlands
    • Posts 31

     Jawahars,

    It's all clear to me now. And i succeeded the implementation of the dynamicstrings.
    So this problem is solved. Thanx for your help.

    The other question i still have is how to deal with the dynamic string with variables

    string currentUser = Membership.GetUser().ProviderUserKey.ToString();


    like: Label1.Text = "Hello" + username  + "You are helping me so fine";
    You see. Now i have 1 string divided into two parts with an variable.
    Still don't figured out how to deal with this one
    Any idea?

    Thanx

  • Re: Multilanguage support on string?

    01-19-2009, 12:54 PM
    • Member
      74 point Member
    • jawahars
    • Member since 04-28-2008, 10:27 AM
    • Chennai,Tamilnadu,India
    • Posts 57

     Hi talsja,

    i dont think there is a difference in working with controls(eg:label) and variable. you try the same way for string as like controls.

    How u solve it for labels. As i said to u or any other way?

     

    -- "Mark As Answer" if my reply helped you --
    Thanks,
    Jawahar
    Lets screw the Technolgies.
Page 1 of 1 (11 items)