spring - 使用内部国际化元素
问题描述
我正在使用 Spring Boot + Thymeleaf。我想国际化这样的事情:
<p>Already registered? <span class="link">Log In</span></p>
如果我添加th:text="#{prompt}"
到<p>
标签,内部span
将被属性值替换。
有没有办法用我的资源包中的一个属性来国际化整个元素的文本?<p>
(可能有占位符或者我不知道)
解决方案
您可以在属性值内为 html 标签添加占位符
财产:
prompt = Already registered? {0}Log In{1};
html:
<p th:utext="#{prompt('<span class=link>', '</span>')}"></p>
注意:我使用th:utext
而不是th:text
因为它不会转义 html。
但是如果你只有两个不同的属性会更清楚。例如:
<p>
<th:block th:text='#{prompt1}'></th:block>
<span class='link' th:text='#{prompt2}'></span>
</p>
推荐阅读
- flutter - 如何访问剪贴板?
- html - 我如何将应用程序/ld 用于租车网站?
- javascript - 量角器 - 将 ControlFlow 更改为 async-await
- php - 页面左侧和顶部有间隙,wordpress 上的背景不会改变
- swift - 构建应用程序时,SKSpritenode 未显示在模拟器或手机中
- arduino - 如何让机器人90度跟随线?
- ios - 使用 AVAssetWriter/AVAssetReader 设置视频帧率的问题
- java - 单击另一个按钮时永久启用一个按钮。即使应用程序重新启动
- r-markdown - 如何在 Distill 中为 R Markdown 文章使用代码折叠?
- powershell - 为什么来自串口事件的 $event.messageData 为空?