YUI recommends YUI3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

This documentation is no longer maintained.

YUI Library Examples: Calendar Control: Localization - Japan

Calendar Control: Localization - Japan

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, how to configure the format of any date strings passed in to the Calendar and how to configure the format of the month, year label used in the header. It uses Japan as an example locale

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"]

The Calendar also provides special configuration properties for determining how date strings and date range strings should be formatted.

These control how strings are parsed when used as input to the Calendar. 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

The following properties are used to format how the month, year label is rendered in the Calendar header:

  • MY_LABEL_MONTH_POSITION - The position of the month in the "month year" date label used in the Calendar header. Default: 1
  • MY_LABEL_YEAR_POSITION - The position of the year in the "month year" date label used in the Calendar header. Default: 2
  • MY_LABEL_MONTH_SUFFIX - The suffix to be added to the month, when rendering the "month year" label in the Calendar header. Default: " "
  • MY_LABEL_YEAR_SUFFIX - The suffix to be added to the year, when rendering the "month year" label in the Calendar header. Default: ""

In our tutorial, we will create a Japanese Calendar that is set up both to accept dates in the standard Japanese format (yyyy/mm/dd) and present the labels in Japanese. Note that all of our date label values will contain special characters in Unicode notation. The Calendar header label will be configured to render the year first, followed by the month, with a year character suffix.

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

Copyright © 2013 Yahoo! Inc. All rights reserved.

Privacy Policy - Copyright Policy - Job Openings