我在 Spring Boot 中使用 thymeleaf,
<span th:text="#{home.welcome}">Welcome Default Message</span>
当在 messages.properties 中找不到 key 时,我有
??home.welcome_en_US??
我不想翻译 messages.properties 中的每条消息。当找不到翻译键消息时,我想在 html 页面中写入“欢迎默认消息”。
我该怎么做?
最佳答案
也许不再相关,但以下内容对我有用。我正在运行 Thymeleaf 3.0.7.RELEASE。
<span th:text="${#strings.defaultString(#messages.msgOrNull('home.welcome'),'Welcome Default Message')}"/>
如果未找到消息,则将 null 传递给 #strings.defaultString 调用,在给定 null 参数时将返回“欢迎默认消息”。
更多信息 http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#strings
关于spring - thymeleaf 国际化使用默认文本 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35115860/