在org.apache.wicket.extensions.yui.calendar.DatePicker中本地化标签

时间:2009-08-20 05:43:14

标签: java localization yui datepicker wicket

有没有人知道如何本地化org.apache.wicket.extensions.yui.calendar.DatePicker的“月”,“年”,“好”和“取消”标签?

根据API,您可以覆盖localize(Map)方法来设置本地化的字符串,但我没有找到相应属性的名称。

4 个答案:

答案 0 :(得分:1)

根据this,您可以通过覆盖DatePicker类的configure方法来本地化标签:

    public class DatePicker extends org.apache.wicket.extensions.yui.calendar.DatePicker {

    @Override
    protected void configure(Map<String, Object> widgetProperties) {
        super.configure(widgetProperties);

        /*
        * var navConfig = {
        *   strings: {
        *   month:"Calendar Month",
        *   year:"Calendar Year",
        *   submit: "Submit",
        *   cancel: "Cancel",
        *   invalidYear: "Please enter a valid year"
        *   },
        * monthFormat: YAHOO.widget.Calendar.SHORT,
        * initialFocus: "month"
        * }
        */

        Map<String, Object> strings = new HashMap<String, Object>();
        strings.put("month", "Месяц");
        strings.put("year", "Год");
        strings.put("submit", "Ok"); // put label for 'Okay' button
        strings.put("cancel", "Отмена"); // put label for 'Cancel' button
        strings.put("invalidYear", "Введите корректный год");

        Map<String, Object> props = new HashMap<String, Object>();
        props.put("strings", strings); // pass localization related parameters
        props.put("monthFormat", "YAHOO.widget.Calendar.SHORT");
        props.put("initialFocus", "year");

        widgetProperties.put("navigator", props);
    }
}

希望您能找到有用的代码段。

答案 1 :(得分:0)

ticket 754添加对localization的支持。

可能patch introduced then可以给你一些线索吗?它引用了:

src/main/java/org/apache/wicket/extensions/yui/calendar/locale/DatePicker_de.properties

使用:

DATE_FIELD_DELIMITER=x
MDY_DAY_POSITION=1
MDY_MONTH_POSITION=2
MDY_YEAR_POSITION=3
MD_DAY_POSITION=1
MD_MONTH_POSITION=2

MONTHS_SHORT=Jan,Feb,M\u00E4r,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez

MONTHS_LONG=Januar,Februar,M\u00E4rz,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember
WEEKDAYS_1CHAR=S,M,D,M,D,F,S
WEEKDAYS_SHORT=So,Mo,Di,Mi,Do,Fr,Sa
WEEKDAYS_MEDIUM=Son,Mon,Die,Mit,Don,Fre,Sam
WEEKDAYS_LONG=Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag

关于标签本身的本地化,您可以尝试:

答案 2 :(得分:0)

我认为你在谈论日历导航器上的标签。这example可能会有所帮助。

答案 3 :(得分:0)

我认为这个解决方案很好:

protected static final String[] NAVIGATOR_LOCALIZATION_KEYS = {
    "month", "year", "submit", "cancel", "invalidYear",
};

In overridden method u should write: 

super.configure(widgetProperties, response, initVariables);
    Map<String, String> strings = MapBuilder.newHashMap();
    for (String key : NAVIGATOR_LOCALIZATION_KEYS) {
        strings.put(key, LocalizationUtils.getString(key));
    }
    widgetProperties.put(
        "navigator", Collections.singletonMap("strings", strings)
    );