Ryan Lundy
Ryan Lundy

Reputation: 210360

ASP.NET localization of text with embedded link...and the link is a server control

I'm working on internationalizing and localizing an ASP.NET app, and I'm running into problems with cases where string literals are mixed with markup. Like this example:

Acme Carpet Retailers <a href="#" class="link" id="ssoLoginUrl" 
    runat="server">click here</a> to log into the site.

For most string literals I'm using the Localize control. I can embed this in a Localize control, tags and all, but the problem is then the link isn't a server control anymore. (It's referenced on the page by its ID.)

I can't really split up the strings ("Acme Carpet Retailers", "click here", etc.) because the word order could be different in a different language.

I've seen several suggestions on how to do this, but they all assume that the text with embedded link is assigned in code, not in markup, and that it's not a server control.

Any advice on how to localize this successfully?

Upvotes: 1

Views: 793

Answers (2)

Julian
Julian

Reputation: 1012

Can't you do just:

<%= String.Format(Resources.MyResource.mydata, 
"<a href=""#"" class=""link"" id=""ssoLoginUrl"" runat=""server"">",
"</a>"
) %>

Then I would have the resource mydata defined as: "{0}click here{1} to log into the site."

Upvotes: 1

Eduardo Molteni
Eduardo Molteni

Reputation: 39453

If the word order could be different in a different language, you have no choice but to localize the entire text (tag included) inside the resx.

But, of course, if this is too troublesome, you can change the app to make the text more structured:

Acme Carpet Retailers <a href="#" class="link" id="ssoLoginUrl" 
runat="server">(Log in here)</a>

Upvotes: 0

Related Questions