Struts2 +国际化+ Java [英] Struts2 + Internationalization + Java

查看:111
本文介绍了Struts2 +国际化+ 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

推荐答案

两者(ab)使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆