Gadgets.i18n (v0.9)
NeedsExamples
- 1 Methods
- 2 JavaScript Internationalization (i18n)
- 2.1 gadgets.i18n.CURRENCY_PATTERN
- 2.2 gadgets.i18n.DECIMAL_PATTERN
- 2.3 gadgets.i18n.FULL_DATE_FORMAT
- 2.4 gadgets.i18n.FULL_DATETIME_FORMAT
- 2.5 gadgets.i18n.FULL_TIME_FORMAT
- 2.6 gadgets.i18n.LONG_DATE_FORMAT
- 2.7 gadgets.i18n.LONG_DATETIME_FORMAT
- 2.8 gadgets.i18n.LONG_TIME_FORMAT
- 2.9 gadgets.i18n.MEDIUM_DATE_FORMAT
- 2.10 gadgets.i18n.MEDIUM_DATETIME_FORMAT
- 2.11 gadgets.i18n.MEDIUM_TIME_FORMAT
- 2.12 gadgets.i18n.PERCENT_PATTERN
- 2.13 gadgets.i18n.SCIENTIFIC_PATTERN
- 2.14 gadgets.i18n.SHORT_DATE_FORMAT
- 2.15 gadgets.i18n.SHORT_DATETIME_FORMAT
- 2.16 gadgets.i18n.SHORT_TIME_FORMAT
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
NameTypeDescription |
Returns
TypeDescription |
Description
This method formats a "Date" object with provided pattern specification. The pattern could be a string using ICU notation or a predefined pattern. A string using ICU notation offers the most flexibility. Each field as specified in the pattern has locale specific behavior. The pattern string is allowed to contain string literals, and one type of pattern might not work for all locales. In those case, the pattern itself could also be locale specific, thus not good for sharing among locales.
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
NameTypeDescription |
Returns
TypeDescription |
Description
Format number using the pattern specified. The pattern could be a string pattern or one of the predefined patterns. The formatted string is returned. If an error is encountered, zero will be returned.
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
NameTypeDescription |
Returns
TypeDescription |
Description
This method will parse the input string ("text"), interpretting it as specified by pattern. The parsed result will be saved into a Date object ("date"). "start" indicates from where in the string the parse should start. This method returns the number of characters consumed.
//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
NameTypeDescription |
Returns
TypeDescription |
Description
Parse string to get a number the pattern specified. The pattern could be a string pattern or one of the predefined patterns.