views:

104

answers:

3

Trying to localize text in ASP.NET labels... want to add a ':' after the localized text. I could just add the ':' to the localized text in the resource file, but that seems silly... there should be an easy way to do this.

<asp:Label id="RoleTypeLabel" runat="server" Text='<%$ Resources: GS3, RoleTypeLabel %>:' AssociatedControlID="RoleTypeDropDown"></asp:Label>

(note the ':' at the end of Text='...')

Of course, this doesn't work... and neither does anything I can think of to concatenate a ':' onto the end of the localized text.

Anyone know how to do it?

TIA, James

+2  A: 

I've always put the colon outside the label.

<asp:Label ID="RoleTypeLabel" runat="server" Text="<%$ Resources: GS3, 
RoleTypeLabel %> />:
Jason Berkan
Duh! Of course! I was putting it between the opening and closing asp:Label, and it was ignoring it. Thinking too complicated when there's a simple solution. Thanks!
James B
Hmm, the only issue I run into is with the padding on the control... I can't have any right-padding on the label, or it pushes the ':' away from the text. But I need an even amount of padding after the colon. Hmm, I'll have to think about that for a bit.
James B
True - I generally use a <span> around the entire label and the colon in order to apply any styles that are required.
Jason Berkan
The span helps, but I had a lot of pain trying to get the text to align... the colon appears either too high up or subscripted. I've tried all combinations of vertical-aligns, but I have to have the right combination of aligns on the label, the colon span, and the textbox to the right. I have it in the right spot, but it took a little voodoo, and if I change padding, margins, or font sizes, I'm back to shuffling aligns.
James B
A: 

why dont you put ':' into the resource file?

mkafkas
The primary reason is that you may re-use the term in a context where a colon is not required (such as a column header).
Jason Berkan
+1  A: 

You could also append the colon using CSS if your labels are positioned appropriately.

label:after
{
    content: ':';
}
Justin R.
That's a cool approach... though I'd probably assign a class to the label so I could only append it to labels that need a ':'
James B
That's fine, too. The magic is in the `:after` pseudo-element.
Justin R.