spring - thymeleaf 国际化使用默认文本 html

标签 spring internationalization spring-boot thymeleaf

我在 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/

相关文章:

java - 如何在 Angular 应用程序上显示来自 springboot 的异常消息

grails - 如何将默认语言设置为英语

spring-boot - 集成测试 - 无法打开 ServletContext 资源/application.properties

java - 在 Spring 中保存两个模型之间的多对多关系

spring-boot - 如何使用 Thymeleaf 在 Spring Boot 中设置 Flash 消息

java - Spring 3.0实现带可选参数的存储过程调用

java - Spring Boot Kafka新手关于序列化/反序列化的问题

java - Tomcat 运行服务而不是 Web 应用程序

grails - 在一页上以不同的语言环境显示文本

javascript - polymer : Uncaught (in promise) ReferenceError: IntlMessageFormat is not defined