全球化和句子中的链接
我正在致力于以 C# 作为后端的 asp.net 应用程序的全球化/本地化。 我们正在将字符串提取到资源文件的过程中,遇到了问题。 我们试图将句子放在一起,以便它们可以翻译,但这对于链接来说是不可能的。 例如:
<%= Strings.BeginningOfSentence %>
<asp:HyperLink id="exampleLink" runat="server"><%= Strings.MiddleOfSentence %></asp:HyperLink>
<%= Strings.EndOfSentence %>
Strings就是资源文件。 如果这是链接的普通 html,我可以使用 String.Format 并将句子放在一起,在 html 中添加作为两个参数,但这会破坏它。 关于如何进行这项工作有什么想法吗?
I am working on globalizing/localizing an asp.net application with C# as the backend. We are in the process of extracting strings to a resource file, and have run into a problem. We are trying to keep sentences together so that they are translatable, but this is not possible with links. For Example:
<%= Strings.BeginningOfSentence %>
<asp:HyperLink id="exampleLink" runat="server"><%= Strings.MiddleOfSentence %></asp:HyperLink>
<%= Strings.EndOfSentence %>
Strings is the resource file. If this were normal html for the link, I could use String.Format and keep the sentence together, adding in the html as two parameters, but that breaks it here. Any ideas in how to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现参数化字符串极大地简化了与动态内容混合的翻译。 例如,您可以在翻译后的字符串中包含占位符,可以在其中插入 link-html。 但这可能会排除服务器端超链接控件的使用。 示例字符串:
英语:
瑞典语:
请注意链接在句子中相对于链接的移动方式(瑞典语版本中链接之前没有文本)。
如果您不想在翻译中包含标记,我想它本身可以用作参数化模板:
然后您可以将翻译后的片段解析到链接 html 中,然后将该片段插入到最终字符串中:
然后您只需需要将结果字符串插入到页面中。
I have found that parameterized strings greatly simplifies translations mixed with dynamic content. For instance, you can have placeholders in the translated string into which link-html can be inserted. This may rule out the use of server-side hyperlink controls though. Example strings:
English:
Swedish:
Note how the link has moved in the sentence in relation to the link (there is no text before the link in the Swedish version).
If you do not want to include the markup in the translation, I guess that may be used as a parameterized template in itself:
Then you can parse translated pieces into the link html, and then insert that piece into the final string:
Then you just need to insert the resulting string into the page.
您不必为此使用 HyperLink 控件,对吗? 如果您需要动态链接,则可以将锚标记存储在参数化字符串中,并使用 string.Format 添加必要的属性值,就像您建议的那样。 像这样的:
代码:
ASPX:
You don't have to use a HyperLink control for this do you? If you need a dynamic link then you can store the anchor tag in a parameterised string and add the necessary attribute values using string.Format, like you suggested. Something like this:
Code:
ASPX: