Gadgets.i18n (v0.9)
From OpenSocial
![]() |
This page does not include any example code. Please help improve this page by adding examples. |
JavaScript Internationalization (i18n)
A container MUST emit the OpenSocial JavaScript internationalization libraries and data files required by the libraries if an application requires the feature <Require feature="opensocial-i18n"/>. The container SHOULD emit the OpenSocial JavaScript internationalization libraries and data files required by the libraries if an application optionallly requests the feature <Optional feature="opensocial-i18n"/>.
Methods
gadgets.i18n.formatDateTime
<static> string gadgets.i18n.formatDateTime(pattern, date)
- Parameters
Name Type Description pattern string/number String to specify patterns or Number used to reference predefined pattern that a date should be formatted into. date Date Date object being formatted.
- Returns
Type Description string string representation of date/time.
- Description
date = new Date(2006, 6, 27, 13, 10, 10, 250); assertEquals("13:10:10", gadgets.i18n.formatDateTime("HH:mm:ss", date));
gadgets.i18n.formatNumber
<static> string gadgets.i18n.formatNumber(pattern, value, opt_currencyCode)
- Parameters
Name Type Description pattern string/number String to specify patterns or Number used to reference predefined pattern that a number should be formatted into. value number The number being formatted. opt_currencyCode string optional international currency code, it determines the currency code/symbol should be used in format/parse. If not given, the currency code for current locale will be used.
- Returns
Type Description string The formatted string.
- Description
var str = gadgets.i18n.formatNumber("#,###", 1234567890); assertEquals("1,234,567,890", str); var str = gadgets.i18n.formatNumber(gadgets.i18n.CURRRENCY_PATTERN, 1234.569); assertEquals("$1,234.58", str);
gadgets.i18n.parseDateTime
<static> number gadgets.i18n.parseDateTime(pattern, text, start, date)
- Parameters
Name Type Description pattern string/number String to specify patterns or Number used to reference predefined pattern that a date should be parsed from. text string The string that need to be parsed. start number The character position in "text" where parse begins. date Date The date object that will hold parsed value.
- Returns
Type Description number The number of characters advanced or 0 if failed.
- Description
//assume locale has already been set to zh_CN var date = new Date(); gadgets.i18n.parseDateTime(gadgets.i18n.LONG_DATE_FORMAT, "2006年7月24日", 0, date); assertEquals(date.getFullYear(), 2006); assertEquals(date.getMonth(), 7 - 1); assertEquals(date.getDate(), 24);
gadgets.i18n.parseNumber
<static> number gadgets.i18n.parseNumber(pattern, text, opt_pos, opt_currencyCode)
- Parameters
Name Type Description pattern string/number String to specify patterns or Number used to reference predefined pattern that a number should be parsed from. text string input text being parsed. opt_pos Array optional one element array that holds position information. It tells from where parse should begin. Upon return, it holds parse stop position. opt_currencyCode string optional international currency code, it determines the currency code/symbol should be used in format/parse. If not given, the currency code for current locale will be used.
- Returns
Type Description number Parsed number, 0 if in error.
- Description
var value = gadgets.i18n.parseNumber("0E0", "1.2345E+4"); assertEquals(12345.0, value); //assume locale has already been set to fr var value = gadgets.i18n.parseNumber(gadgets.i18n.CURRENCY_PATTERN, "0,30 €"); assertEquals(0.30, value);
JavaScript Internationalization (i18n)
A container MUST emit the OpenSocial JavaScript internationalization libraries and data files required by the libraries if an application requires the feature <Require feature="opensocial-i18n"/>. The container SHOULD emit the OpenSocial JavaScript internationalization libraries and data files required by the libraries if an application optionallly requests the feature <Optional feature="opensocial-i18n"/>.
gadgets.i18n.CURRENCY_PATTERN
- Pattern for currency.
gadgets.i18n.DECIMAL_PATTERN
- Pattern for decimal numbers.
gadgets.i18n.FULL_DATE_FORMAT
- Format for full representations of dates.
gadgets.i18n.FULL_DATETIME_FORMAT
- Format for short representations of datetimes.
gadgets.i18n.FULL_TIME_FORMAT
- Format for full representations of times.
gadgets.i18n.LONG_DATE_FORMAT
- Format for long representations of dates.
gadgets.i18n.LONG_DATETIME_FORMAT
- Format for short representations of datetimes.
gadgets.i18n.LONG_TIME_FORMAT
- Format for long representations of times.
gadgets.i18n.MEDIUM_DATE_FORMAT
- Format for medium representations of dates.
gadgets.i18n.MEDIUM_DATETIME_FORMAT
- Format for medium representations of datetimes.
gadgets.i18n.MEDIUM_TIME_FORMAT
- Format for medium representations of times.
gadgets.i18n.PERCENT_PATTERN
- Pattern for percentages.
gadgets.i18n.SCIENTIFIC_PATTERN
- Pattern for scientific numbers.
gadgets.i18n.SHORT_DATE_FORMAT
- Format for short representations of dates.
gadgets.i18n.SHORT_DATETIME_FORMAT
- Format for short representations of datetimes.
gadgets.i18n.SHORT_TIME_FORMAT
- Format for short representations of times.
| OpenSocial (v0.9) | |||
| opensocial |
gadgets.i18n | ||

