YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Calendar Control: Localization - Germany

# Calendar Control: Localization - Germany

Calendar provides configuration properties that can be used to change the Calendar's various data labels, when the Calendar is used in different locales. This example shows how to provide locale specific labels for month and weekday names, as well as how to configure the expected format of any date strings passed in to the Calendar. It uses Germany as an example locale

View example in new window.

## Setting up the Calendar

There are several properties that are used to change localization settings:

- LOCALE_MONTHS - The setting that determines which length of month labels should be used. Possible values are "short" and "long".
- LOCALE_WEEKDAYS - The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long".
- MONTHS_SHORT - The short month labels for the current locale. Default: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
- MONTHS_LONG - The long month labels for the current locale. Default: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
- WEEKDAYS_1CHAR - The 1-character weekday labels for the current locale. Default: ["S", "M", "T", "W", "T", "F", "S"]
- WEEKDAYS_SHORT - The short weekday labels for the current locale. Default: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
- WEEKDAYS_MEDIUM - The medium weekday labels for the current locale. Default: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
- WEEKDAYS_LONG - The long weekday labels for the current locale. Default: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

In addition, the Calendar provides special configuration properties for determining how incoming dates and date ranges should be formatted. By default, the date format for input to the Calendar is mm/dd/yyyy. Ranges are separated by a dash ("-") and lists of dates are delimited using a comma (","). Using these properties, the initial formatting of date can be easily modified:

- DATE_DELIMITER - The value used to delimit individual dates in a date string passed to various Calendar functions. Default: ","
- DATE_FIELD_DELIMITER - The value used to delimit date fields in a date string passed to various Calendar functions. Default: "/"
- DATE_RANGE_DELIMITER - The value used to delimit date ranges in a date string passed to various Calendar functions. Default: "-"
- MDY_MONTH_POSITION - The position of the month in a month/day/year date string. Default: 1
- MDY_DAY_POSITION - The position of the day in a month/day/year date string. Default: 2
- MDY_YEAR_POSITION - The position of the year in a month/day/year date string. Default: 3
- MD_MONTH_POSITION - The position of the month in a month/day date string. Default: 1
- MD_DAY_POSITION - The position of the day in a month/day date string. Default: 2
- MY_MONTH_POSITION - The position of the month in a month/year date string. Default: 1
- MY_YEAR_POSITION - The position of the year in a month/year date string. Default: 2

In our tutorial, we will create a German Calendar that is set up both to accept dates in the standard German format (dd.mm.yyyy) and present the labels in German. Note that all of our date label values will contain special characters in Unicode notation. Also, we will present the weekday labels in the "short" format, which will amount to 2 characters in this example.

YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", { LOCALE_WEEKDAYS:"short", START_WEEKDAY: 1, MULTI_SELECT: true } ); // Correct formats for Germany: dd.mm.yyyy, dd.mm, mm.yyyy YAHOO.example.calendar.cal1.cfg.setProperty("DATE_FIELD_DELIMITER", "."); YAHOO.example.calendar.cal1.cfg.setProperty("MDY_DAY_POSITION", 1); YAHOO.example.calendar.cal1.cfg.setProperty("MDY_MONTH_POSITION", 2); YAHOO.example.calendar.cal1.cfg.setProperty("MDY_YEAR_POSITION", 3); YAHOO.example.calendar.cal1.cfg.setProperty("MD_DAY_POSITION", 1); YAHOO.example.calendar.cal1.cfg.setProperty("MD_MONTH_POSITION", 2); // Date labels for German locale YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_SHORT", ["Jan", "Feb", "M\u00E4r", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]); YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_LONG", ["Januar", "Februar", "M\u00E4rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]); YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_1CHAR", ["S", "M", "D", "M", "D", "F", "S"]); YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_SHORT", ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]); YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_MEDIUM",["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"]); YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_LONG", ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]);

Next, we can set some selected dates and the current pagedate using our newly configured date format, and render the Calendar:

YAHOO.example.calendar.cal1.select("1.10.2006-8.10.2006"); YAHOO.example.calendar.cal1.cfg.setProperty("PAGEDATE", "10.2006"); YAHOO.example.calendar.cal1.render();

### Calendar Control Examples:

- Quickstart Tutorial
- Multi-Select Calendar
- Multi-Page Calendar
- Minimum/Maximum Dates
- Calendar Navigator
- Handling Calendar Events
- Calendar and Text Fields
- Calendar and Select Fields
- Using the Render Stack
- Popup Calendar
- Localization - Germany
- Localization - Japan
- Calendar inside a Container
- Interval Selection Calendar
- Skinning The Calendar
- Calendar Plugin (included with examples for Rich Text Editor)
- Inline Cell Editing (included with examples for DataTable Control)
- Using YUI Loader to Load the Calendar Control (included with examples for YUI Loader Utility (beta))
- Simple Calendar Menu Button (included with examples for Button Control)
- Calendar Menu Button with Date on Button Face (included with examples for Button Control)
- Simple Application (included with examples for Layout Manager)
- Complex Application (included with examples for Layout Manager)
- Simple Profiling (included with examples for ProfilerViewer Control (beta))

### More Calendar Control Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings