如何在运行时填写资源字符串?
我有一个想要本地化的应用程序。但是,要本地化的字符串有时包含我想在运行时提供的部分,例如操作链接。
例如,我有一个像这样的字符串: Please click here寻求帮助。
我不能将其分成两个资源,因为在不同的语言中它会位于不同的位置。
有什么方法可以做到这一点,还是我应该坚持将控制器/操作的链接硬编码到资源本身中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该这样修改您的字符串:
现在,即使您的文本顺序发生变化,第一个字符串
“Please {0]click here{1} for help”
也可以轻松翻译/本地化:You should modify your string this way:
Now, the first string
"Please {0]click here{1} for help"
can be easily translated/localized, even if the order of your text changes:我最终采用的方法是创建一个如下所示的资源字符串:
然后使用 String.Format 和我已经定义的
"Click Here"
资源在运行时填充该字符串。The approach I ended up taking was creating a resource string like this:
Which would then be filled at run-time using a String.Format and a resource for
"Click Here"
which I already had defined.