programing

Spring 3 / Thymeleaf에서 매개변수를 사용하여 지역화 메시지를 표시하는 방법

minimums 2023. 9. 10. 12:07
반응형

Spring 3 / Thymeleaf에서 매개변수를 사용하여 지역화 메시지를 표시하는 방법

Spring 3과 Thymeleaf를 사용하여 웹 페이지를 만들고 있는데 다음과 같은 메시지를 표시하는 방법을 잃었습니다.

어서오세요.message=안녕하세요 {0}, 어서 오세요!

{0}을(를) Thymeleaf 태그 내부의 사용자 이름으로 바꿉니다.

<h1 th:text="#{welcome.message}">Welcome Placeholder</h1>

{0}이(가) 번들 메시지의 구문이 올바른지도 잘 모르겠습니다.

사용가능

#{welcome.message(${some.attribute})}

어디에some.attribute교체할 때 사용할 값이 될 것입니다.{0}.

값을 쉼표로 구분할 수 있어야 합니다.()사용할 값을 더 추가합니다.

계산된 메시지 키를 매개 변수로 사용할 수도 있습니다.

<p th:text="#{messages.msg1(${param1})}"></p>
<p th:text="#{messages.msg2(${param2},${param3})}"></p>
<p th:text="#{messages.msg3(#{${param4}})}"></p>

위에서 [msg3]의 매개 변수는 키 자체가 [${param4}] 계산되는 메시지 키 [#{key}]입니다.국제화된 메시지에 국제화된 계산 조각을 삽입할 수 있다는 장점이 있습니다.

배열 크기를 알 수 없는 파라미터 배열을 전달해야 하는 경우 다음을 사용할 수 있습니다.

<p th:text="${#messages.msgWithParams(messageKey, messageParams)}"></p>
<!-- or -->
<p th:text="${#messages.msgOrNullWithParams(messageKey, messageParams)}"></p>

https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#messages-1

언급URL : https://stackoverflow.com/questions/20789441/how-to-show-localization-messages-with-parameters-in-spring-3-thymeleaf

반응형