Last post Jan 19, 2009 12:54 PM by jawahars
Jan 10, 2009 07:04 AM|talsja|LINK
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:Label id="Label1" runat="server" text="" />
Label1.Text = "Here is my message for label1";
Now the question is how do i localize this Label?
Thanx in advance
Jan 10, 2009 07:57 AM|XIII|LINK
take a look at this tutorial:
How Do I: Create a Multi-Lingual Site with Localization?
Jan 10, 2009 11:18 AM|talsja|LINK
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
Jan 10, 2009 12:53 PM|XIII|LINK
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.
Jan 14, 2009 07:00 PM|talsja|LINK
Okay, but what about this:
Label1.Text = ""/>
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?
Jan 16, 2009 02:03 AM|jawahars|LINK
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
follow these steps:
i think u already have resx files?
first resx file
second resx file
store that text in corresponding .resx file in name-value pair
now move to code behind:
add the code
Label1.Text = Me.GetLocalResourceObject("truevalue")
else if (false)
Label1.Text = Me.GetLocalResourceObject("falsevalue")
local resource asp:Localize culture
Jan 17, 2009 05:41 PM|talsja|LINK
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
Jan 17, 2009 06:03 PM|talsja|LINK
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
Jan 19, 2009 04:14 AM|jawahars|LINK
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
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:
lblTest.text = Me.GetLocalResourceObject("truevalue")
lblTest.text = Me.GetLocalResourceObject("falsevalue")
Jan 19, 2009 08:28 AM|talsja|LINK
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
Jan 19, 2009 12:54 PM|jawahars|LINK
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?