[英]Syntax explanation of LocaleResolver and LocaleChangeInterceptor
1)I understand that the syntax for CookieLocaleResolver is as follows: 1)我了解CookieLocaleResolver的语法如下:
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieName" value="clientlanguage"/>
What I understand is this resolver searches for all cookies in the request whose value might match a locale ..so property name is set as "Cookie Name" but why is the value also set ..is it that we are replacing the locale value in the respective cookie by this. 我了解的是,此解析器在请求中搜索其值可能与语言环境..so匹配的所有cookie,因此将属性名称设置为“ Cookie名称”,但为什么还要设置该值,也是否要替换。相应的cookie。
2)Is it possible to change the locale without sing the LocaleChangeInterceptor? 2)是否可以在不使用LocaleChangeInterceptor的情况下更改语言环境?
3)In SessionLocaleResolver what does the following property signify: 3)在SessionLocaleResolver中,以下属性表示什么:
<property name="defaultName" value="clientlanguage"/>
and how does the SessionLocale work? 以及SessionLocale如何工作?
In CookieLocaleResolver
you need to specify the name of the cookie. 在
CookieLocaleResolver
您需要指定cookie的名称。 It searches for a specific cookie, not for any cookie containing locale-like value. 它搜索特定的cookie,而不搜索任何包含类似语言环境的值的cookie。 In your example the cookie will be named
clientlanguage
. 在您的示例中,cookie的名称为
clientlanguage
。
SessionLocaleResolver
stores the client locale in user session. SessionLocaleResolver
在用户会话中存储客户端语言环境。 There is no property defaultName
on this bean. 此bean上没有属性
defaultName
。 However there is defaultLocale
property (similar property is also on CookieLocaleResolver
), where you can set what should be the default locale if the user didn't explicitly switch to a different one. 但是,存在
defaultLocale
属性( CookieLocaleResolver
上也有类似属性),如果用户未明确切换到其他语言环境,则可以在其中设置默认语言环境。
Ad. 广告。 changing locale - you can change locale just by calling
localeResolver.setLocale(...)
. 更改语言环境-您可以仅通过调用
localeResolver.setLocale(...)
来更改语言环境。 That is what LocaleChangeInterceptor
is doing. 这就是
LocaleChangeInterceptor
所做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.