开发者

How do you fill in a resource string at run-time?

I have an application I'd like to localise. However, the strings to be localised occasionally contain parts I'd like to provide at runtime, such as action links.

For example, I have a string like this: Please <a href="/help">click here</a> for help. I can't just split it into two resources since in different languages 开发者_如何学编程it'll be in a different location.

Is there any way to do this or should I stick to hard-coding the link to the controller/action in the resource itself?


You should modify your string this way:

 string.Format("Please {0]click here{1} for help", "<a href="/help">","</a>")

Now, the first string "Please {0]click here{1} for help" can be easily translated/localized, even if the order of your text changes:

"Für Hilfe klicken Sie bitte {0}hier{1}."


The approach I ended up taking was creating a resource string like this:

"Please {0} for help."

Which would then be filled at run-time using a String.Format and a resource for "Click Here" which I already had defined.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜