James King
James King

Reputation: 6353

Concatenating text in an ASP.NET localized label

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

Upvotes: 3

Views: 3242

Answers (5)

weienw
weienw

Reputation: 832

You should include the colon as part of the string that you mean to translate. See #3 in this 12 Commandments of Software Localization article, which explains that punctuation often needs to be translated. For example, French adds a space before the colon, and languages like Arminian or Greek may use a different symbol in the colon's place.

As for reusing terms, consider that "Due:" and "Due" are different enough linguistically that you're better of translating them individually.

Upvotes: 0

Andrew Charlton
Andrew Charlton

Reputation: 350

Just ran into a similar situation as I went back and localized one of our apps. Ended up using a Literal control inside the Label:

<asp:Label AssociatedControlID="txt" CssClass="class" ID="lbl" runat="server">
    * <asp:Literal runat="server" Text="<%$ Resources:Words, labelText %>" />:
</asp:Label>

We were using some CSS to right align form labels with a fixed width so any text outside of the label actually broke our pages. The accepted answer is most straight forward, but might not work in all situations.

Upvotes: 0

Justin Rusbatch
Justin Rusbatch

Reputation: 4052

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

label:after
{
    content: ':';
}

Upvotes: 1

mkafkas
mkafkas

Reputation: 99

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

Upvotes: 1

Jason Berkan
Jason Berkan

Reputation: 8914

I've always put the colon outside the label.

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

Upvotes: 4

Related Questions