Struts2 +国际化+ Java [英] Struts2 + Internationalization + Java
问题描述
我正在使用Struts2国际化来支持英语和英语.阿拉伯语.
I am using Struts2 Internationalization to support English & Arabic.
我想知道,当区域设置更改时,是否可以动态或自动更改在任何输入(文本,日期等)之前出现的标签的位置?
I want to know that is it possible to dynamically or automatically change the position of label which comes before any input (text, date, etc.) when the locale changes?
例如
LTR->英文->名字-输入文本框"
LTR -> English -> First Name - "Input Text Box"
RTL->阿拉伯语->输入文本框"-أولاسم
RTL -> Arabic -> "Input Text Box" - أول اسم
对此有什么可能的解决方案?
Any possible solution for this?
BR SC
推荐答案
Either (ab)use java.awt.ComponentOrientation
String direction = ComponentOrientation.getOrientation(locale).isLeftToRight() ? "ltr" : "rtl";
(尽管它的源代码相当简单,只有4种语言是RTL,这是相关的摘录)
(its source code is pretty trivial though, there are only 4 languages which are RTL, here's an extract of relevance)
public static ComponentOrientation getOrientation(Locale locale) {
String lang = locale.getLanguage();
if ("iw".equals(lang) || "ar".equals(lang) || "fa".equals(lang) || "ur".equals(lang)) {
return RIGHT_TO_LEFT;
} else {
return LEFT_TO_RIGHT;
}
}
或自己将其放入重新包装中.
Or put it in a recourcebundle yourself.
this.direction = ltr
并阅读如下
String direction = bundle.getString("this.direction");
无论哪种方式,您都可以利用它来相应地更改方向.
Either way, you can make use of this to change the direction accordingly.
<html dir="${direction}">
在生成的HTML中最终将以<html dir="ltr">
或<html dir="rtl">
的形式出现.
which would end up as <html dir="ltr">
or <html dir="rtl">
in generated HTML.
这篇关于Struts2 +国际化+ Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!