Spring Boot Thymeleaf 国际化 i18n

Spring Boot Thymeleaf i18n About 549 words

语法

#{}

示例

th:text中使用#{}引入Resource Bundle中的i18n资源。

<a th:text="#{header_home}" th:href="@{/}">首页</a>

<a th:text="#{header_search}" th:href="@{/search.html}">搜索</a>

YAML 配置

spring:
  messages:
    basename: file:${user.dir}/i18n/messages,classpath:i18n/messages
    cache-duration: 1h
    fallback-to-system-locale: true
  web:
    locale: en

i18n 文件

messages.properties

header_home=HOME
header_search=SEARCH

messages_en.properties

header_home=HOME
header_search=SEARCH

messages_zh.properties

header_home=首页
header_search=搜索
Views: 516 · Posted: 2023-08-17

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh