JSF2 中的图像 i18n
我正在尝试本地化 JSF 中的图像,并且希望用户能够在我的网站上设置他们的区域设置。 方法来完成此操作
FacesContext.getCurrentInstance().getViewRoot().setLocale(_locale);
我通过调用效果很好的
<h:graphicImage library="images" name="pic.gif" />
,但有一个例外:使用浏览器请求中发送的 Accept-Language
来确定要使用的区域设置。我可以通过在每个 .properties
文件中放置一个区域设置字符串并引用图像来解决这个问题,
<h:graphicImage library="#{resource.locale}/images" name="pic.gif" />
但是单个图像没有后备,所以我必须拥有每个图像的副本,无论是在每个语言环境的目录中,它都不同或不同。鉴于我支持 9 个语言环境,并且将来可能会支持更多语言环境,这相当麻烦。任何建议将不胜感激。
I am trying to localize images in JSF, and I want the user to be able to set their locale on my site. This I am doing by a call to
FacesContext.getCurrentInstance().getViewRoot().setLocale(_locale);
which works great, with one exception:
<h:graphicImage library="images" name="pic.gif" />
uses the Accept-Language
sent in the browser's request to determine which locale to use. I can work around this by placing a locale string in each .properties
file and referencing images by
<h:graphicImage library="#{resource.locale}/images" name="pic.gif" />
but then there is no fall-back for individual images, so I have to have a copy of every image, whether it is different or not, in every locale's directory. This is quite cumbersome, given that I support 9 locales and probably more in the future. Any advice would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的问题。然而,JSF 和 Java EE 的残余都没有对此提供内置支持。最好的选择是创建一个了解后备语言环境的
Servlet
,从而基本上执行以下测试:您最终可以通过执行相同检查的自定义 JSF 组件来执行此操作。
Interesting issue. There is however no builtin support for this, not by JSF nor by remnant of Java EE. Your best bet is to create a
Servlet
which knows about the fallback locale and thus basically does the following test:You could eventually do this by a custom JSF component which does the same check.