2017-05-26 84 views
1

我无法像使用常规文本那样找到在占位符内部文本国际化的方式。我希望把我的国际化:=“S”占位符=“搜索嗜好”春季占位符的国际化

输入类型=“文本”级=“表单控制”的名字与输入类型=“文本”类= “表单控制” NAME = “S” 占位符= “ctrlpanel.search.placeholder”

ctrlpanel.search.placeholder =搜索嗜好

现在,在我的JSP我包括标签

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> 
 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
 

 
<c:set var="contextRoot" value="${pageContext.request.contextPath}" /> 
 
<c:url var="search" value="/search" /> 
 

 

 
<hr/> 
 
<div class="row"> 
 
\t <div class="col-md-8 col-md-offset-2"> 
 
\t \t <form action="${search}" method="post"> 
 
\t \t \t <input type="hidden" name="${_csrf.parameterName}" 
 
\t \t \t \t value="${_csrf.token}" /> 
 
\t \t \t <div class="input-group input-group-lg"> 
 
\t \t \t \t <input type="text" class="form-control" name="s" placeHolder="Search Hobbies"> 
 
\t \t \t \t <span class="input-group-btn"> 
 
\t \t \t \t \t <button id="search-button" class="btn btn-primary" type="submit"> 
 
\t \t \t \t \t <spring:message code="ctrlpanel.find.button" text="default text" /> 
 
\t \t \t \t \t </button> 
 
\t \t \t \t </span> \t \t \t 
 
\t \t \t </div> 
 
\t \t </form> 
 
\t </div> 
 
</div>

我的配置能正常工作:

package com.caveofprogramming.configuration; 

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.web.servlet.LocaleResolver; 
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; 
import org.springframework.web.servlet.i18n.SessionLocaleResolver; 

import java.util.Locale; 


@Configuration 
public class SpringMvcConfiguration extends WebMvcConfigurerAdapter { 

    @Bean 
    public LocaleResolver localeResolver(){ 
     SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver(); 
     sessionLocaleResolver.setDefaultLocale(new Locale("es", "ES")); 
     //sessionLocaleResolver.setDefaultLocale(Locale.US); 
     return sessionLocaleResolver; 
    } 

    @Bean 
    LocaleChangeInterceptor localeChangeInterceptor(){ 
     LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); 
     localeChangeInterceptor.setParamName("lang"); 
     return localeChangeInterceptor; 
    } 

    @Override 
    public void addInterceptors(InterceptorRegistry interceptorRegistry){ 
     interceptorRegistry.addInterceptor(localeChangeInterceptor()); 
    } 
} 

由于这是行不通的。

<input type="text" class="form-control" name="s" placeHolder="<spring:message code="ctrlpanel.search.placeholder"/>">
弹簧的

+0

是什么让你认为你不能做它就像你正在做的“普通文本”? –

回答

2

使用var属性:其结合的结果页面,请求,会话或应用程序范围时使用的消息。

<spring:message code="ctrlpanel.search.placeholder" var="searchPlaceholder"/> 

,然后更新您的输入字段这样的:

<input type="text" class="form-control" name="s" placeHolder="${searchPlaceholder}">