/**
* Return the names of months and weekdays as a script.
*/
protected void addCalenderTranslations(List<Element> headElements) {
JsScript script = new JsScript();
script.setId("datefield-js-setup-global");
if (!headElements.contains(script)) {
DateFormatSymbols dfs = new DateFormatSymbols(getLocale());
HtmlStringBuffer buffer = new HtmlStringBuffer(150);
buffer.append("Date.months=new Array(");
generateJavaScriptArray(buffer, dfs.getMonths(), 0, 12);
buffer.append(");\n");
buffer.append("Date.monthAbbreviations=new Array(");
generateJavaScriptArray(buffer, dfs.getShortMonths(), 0, 12);
buffer.append(");\n");
buffer.append("Date.dayNames=new Array(");
generateJavaScriptArray(buffer, dfs.getWeekdays(),
Calendar.SUNDAY, Calendar.SATURDAY + 1);
buffer.append(");\n");
buffer.append("Date.dayAbbreviations=new Array(");
generateJavaScriptArray(buffer, dfs.getShortWeekdays(),
Calendar.SUNDAY, Calendar.SATURDAY + 1);
buffer.append(");\n");
String[] weekdays = null;
if (getMessages().containsKey("calendar-weekdays-heading")) {
String headings = getMessage("calendar-weekdays-heading");
weekdays = StringUtils.splitPreserveAllTokens("," + headings, ',');
} else {
weekdays = dfs.getShortWeekdays();
}
String[] days = new String[7];
int firstDayOfWeek = getFirstDayOfWeek() - 1;
for (int i = 0; i < 7; i++) {
days[i] = weekdays[(i + firstDayOfWeek) % 7 + 1];
}
buffer.append("Date.weekdays=new Array(");
generateJavaScriptArray(buffer, days, 0, 7);
buffer.append(");\n");
buffer.append("Date.first_day_of_week=").append(firstDayOfWeek).append(";\n");
if (getMessages().containsKey("calendar-ok")) {
buffer.append("_translations[\"OK\"] = \"");
buffer.append(getMessage("calendar-ok"));
buffer.append("\";\n");
}
if (getMessages().containsKey("calendar-now")) {
buffer.append("_translations[\"Now\"] = \"");
buffer.append(getMessage("calendar-now"));
buffer.append("\";\n");
}
if (getMessages().containsKey("calendar-today")) {
buffer.append("_translations[\"Today\"] = \"");
buffer.append(getMessage("calendar-today"));
buffer.append("\";\n");
}
if (getMessages().containsKey("calendar-clear")) {
buffer.append("_translations[\"Clear\"] = \"");
buffer.append(getMessage("calendar-clear"));
buffer.append("\";\n");
}
script.setContent(buffer.toString());
headElements.add(script);
}
}