Spring Web MVC 中区域设置的多个默认值?
我希望我的基于 Spring-MVC 的 Web 应用程序在传入 CZ 语言环境时默认为 SK 语言环境,但任何其他语言环境应默认为 EN。
当从具有捷克语或斯洛伐克语区域设置的计算机访问时,我正在设计的网站应自动以斯洛伐克语显示。否则,该网站应该默认为英语。我怎样才能做到这一点?我应该子类化 org.springframework.web.servlet.i18n.LocaleChangeInterceptor 并编写自定义代码,还是有一种仅配置的方法来实现此目的?我可以想象德语国家可能有同样的要求,比如如果从德国或奥地利访问则默认为 DE,否则默认为 EN...
I would like my Spring-MVC-based web application to default to SK locale when CZ locale is passed in, however any other locale should default to EN.
The site I am designing should automatically display in Slovak language when visited from a computer with either a Czech or Slovak locale setting. Otherwise, the site should just default to English. How could I achieve this? Should I subclass the org.springframework.web.servlet.i18n.LocaleChangeInterceptor
and write custom code, or is there a config-only way of achieving this? I can imagine that German speaking countries could have the same sort of requirement, like default to DE if visited from Germany or Austria, otherwise default to EN...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要子类化 LocaleChangeInterceptor 。 LocaleChangeInterceptor 通过请求参数 'Locale' 检测区域设置的更改。
您需要配置拦截器和区域设置特定的属性文件。之后,您可以用来
显示它们。检查 此处获取示例配置。
您还可以使用 CookieLocaleResolver,它是一个“LocaleResolver 实现,在自定义设置的情况下使用发送回用户的 cookie,并回退到指定的默认区域设置或请求的接受标头区域设置。”
You will not need to subclass LocaleChangeInterceptor . LocaleChangeInterceptor detects change in locale via a request parameter 'Locale' .
You'll need to configure the interceptor and locale specific property files . After this you could use
to display them.Check here for a sample configuration.
You could also use CookieLocaleResolver which is a "LocaleResolver implementation that uses a cookie sent back to the user in case of a custom setting, with a fallback to the specified default locale or the request's accept-header locale. "