【问题标题】:Internationalization in the Spring projectSpring项目中的国际化
【发布时间】:2017-12-12 22:17:50
【问题描述】:
我为我的应用程序创建了国际化,我想知道我是否可以创建多个文件来创建翻译后的消息。我不认为这是可取的,但我更愿意问。
问题是我有一个“messages.properties”文件,其中已经有一些文本
http s://pastebin.com/WdyE0Aaj
而这仅仅是个开始。如果我有几十页,每页我都必须在这里声明翻译。毕竟,这个文件会持续成百上千。能否以某种方式分成更多文件?
【问题讨论】:
标签:
java
spring
spring-mvc
spring-boot
thymeleaf
【解决方案1】:
当然可以(并且可能应该,以保持事情的可维护性)。
Spring-boot reference 说:
spring.messages.basename=messages # Comma-separated list of basenames, each following the ResourceBundle convention.
因此,只需将任意数量的基本名称添加到您的 Spring Boot 属性/yaml 文件中,它们就会全部聚合在一个 MessageSource 中。只需确保避免 i18n 属性名称冲突。