| Index: src/extensions/experimental/i18n.js
|
| diff --git a/src/extensions/experimental/i18n.js b/src/extensions/experimental/i18n.js
|
| index 022e763e664546214523ade7de97a6d19c3c9ba1..0fa7ae72b0a9fb9d1f4ba050bc0ff485b5908afe 100644
|
| --- a/src/extensions/experimental/i18n.js
|
| +++ b/src/extensions/experimental/i18n.js
|
| @@ -45,11 +45,11 @@ v8Locale = function(settings) {
|
| }
|
|
|
| var properties = NativeJSLocale(
|
| - v8Locale.__createSettingsOrDefault(settings, {'localeID': 'root'}));
|
| + v8Locale.createSettingsOrDefault_(settings, {'localeID': 'root'}));
|
|
|
| // Keep the resolved ICU locale ID around to avoid resolving localeID to
|
| // ICU locale ID every time BreakIterator, Collator and so forth are called.
|
| - this.__icuLocaleID = properties.icuLocaleID;
|
| + this.__icuLocaleID__ = properties.icuLocaleID;
|
| this.options = {'localeID': properties.localeID,
|
| 'regionID': properties.regionID};
|
| };
|
| @@ -61,7 +61,7 @@ v8Locale = function(settings) {
|
| */
|
| v8Locale.prototype.derive = function(settings) {
|
| return new v8Locale(
|
| - v8Locale.__createSettingsOrDefault(settings, this.options));
|
| + v8Locale.createSettingsOrDefault_(settings, this.options));
|
| };
|
|
|
| /**
|
| @@ -79,9 +79,9 @@ v8Locale.prototype.derive = function(settings) {
|
| v8Locale.v8BreakIterator = function(locale, type) {
|
| native function NativeJSBreakIterator();
|
|
|
| - locale = v8Locale.__createLocaleOrDefault(locale);
|
| + locale = v8Locale.createLocaleOrDefault_(locale);
|
| // BCP47 ID would work in this case, but we use ICU locale for consistency.
|
| - var iterator = NativeJSBreakIterator(locale.__icuLocaleID, type);
|
| + var iterator = NativeJSBreakIterator(locale.__icuLocaleID__, type);
|
| iterator.type = type;
|
| return iterator;
|
| };
|
| @@ -122,103 +122,22 @@ v8Locale.prototype.v8CreateBreakIterator = function(type) {
|
| v8Locale.Collator = function(locale, settings) {
|
| native function NativeJSCollator();
|
|
|
| - locale = v8Locale.__createLocaleOrDefault(locale);
|
| + locale = v8Locale.createLocaleOrDefault_(locale);
|
| var collator = NativeJSCollator(
|
| - locale.__icuLocaleID, v8Locale.__createSettingsOrDefault(settings, {}));
|
| + locale.__icuLocaleID__, v8Locale.createSettingsOrDefault_(settings, {}));
|
| return collator;
|
| };
|
|
|
| /**
|
| * Creates new Collator based on current locale.
|
| * @param {Object} - collation flags. See constructor.
|
| - * @returns {Object} - new Collator object.
|
| + * @returns {Object} - new v8BreakIterator object.
|
| */
|
| v8Locale.prototype.createCollator = function(settings) {
|
| return new v8Locale.Collator(this, settings);
|
| };
|
|
|
| /**
|
| - * DateTimeFormat class implements locale-aware date and time formatting.
|
| - * Constructor is not part of public API.
|
| - * @param {Object} locale - locale object to pass to formatter.
|
| - * @param {Object} settings - formatting flags:
|
| - * - skeleton
|
| - * - dateType
|
| - * - timeType
|
| - * - calendar
|
| - * @constructor
|
| - */
|
| -v8Locale.__DateTimeFormat = function(locale, settings) {
|
| - native function NativeJSDateTimeFormat();
|
| -
|
| - settings = v8Locale.__createSettingsOrDefault(settings, {});
|
| -
|
| - var cleanSettings = {};
|
| - if (settings.hasOwnProperty('skeleton')) {
|
| - cleanSettings['skeleton'] = settings['skeleton'];
|
| - } else {
|
| - cleanSettings = {};
|
| - if (settings.hasOwnProperty('dateType')) {
|
| - var dt = settings['dateType'];
|
| - if (!/^short|medium|long|full$/.test(dt)) dt = 'short';
|
| - cleanSettings['dateType'] = dt;
|
| - }
|
| -
|
| - if (settings.hasOwnProperty('timeType')) {
|
| - var tt = settings['timeType'];
|
| - if (!/^short|medium|long|full$/.test(tt)) tt = 'short';
|
| - cleanSettings['timeType'] = tt;
|
| - }
|
| - }
|
| -
|
| - // Default is to show short date and time.
|
| - if (!cleanSettings.hasOwnProperty('skeleton') &&
|
| - !cleanSettings.hasOwnProperty('dateType') &&
|
| - !cleanSettings.hasOwnProperty('timeType')) {
|
| - cleanSettings = {'dateType': 'short',
|
| - 'timeType': 'short'};
|
| - }
|
| -
|
| - locale = v8Locale.__createLocaleOrDefault(locale);
|
| - var formatter = NativeJSDateTimeFormat(locale.__icuLocaleID, cleanSettings);
|
| -
|
| - // NativeJSDateTimeFormat creates formatter.options for us, we just need
|
| - // to append actual settings to it.
|
| - for (key in cleanSettings) {
|
| - formatter.options[key] = cleanSettings[key];
|
| - }
|
| -
|
| - /**
|
| - * Clones existing date time format with possible overrides for some
|
| - * of the options.
|
| - * @param {!Object} overrideSettings - overrides for current format settings.
|
| - * @returns {Object} - new DateTimeFormat object.
|
| - */
|
| - formatter.derive = function(overrideSettings) {
|
| - // To remove a setting user can specify undefined as its value. We'll remove
|
| - // it from the map in that case.
|
| - for (var prop in overrideSettings) {
|
| - if (settings.hasOwnProperty(prop) && !overrideSettings[prop]) {
|
| - delete settings[prop];
|
| - }
|
| - }
|
| - return new v8Locale.__DateTimeFormat(
|
| - locale, v8Locale.__createSettingsOrDefault(overrideSettings, settings));
|
| - };
|
| -
|
| - return formatter;
|
| -};
|
| -
|
| -/**
|
| - * Creates new DateTimeFormat based on current locale.
|
| - * @param {Object} - formatting flags. See constructor.
|
| - * @returns {Object} - new DateTimeFormat object.
|
| - */
|
| -v8Locale.prototype.createDateTimeFormat = function(settings) {
|
| - return new v8Locale.__DateTimeFormat(this, settings);
|
| -};
|
| -
|
| -/**
|
| * Merges user settings and defaults.
|
| * Settings that are not of object type are rejected.
|
| * Actual property values are not validated, but whitespace is trimmed if they
|
| @@ -227,7 +146,7 @@ v8Locale.prototype.createDateTimeFormat = function(settings) {
|
| * @param {!Object} defaults - default values for this type of settings.
|
| * @returns {Object} - valid settings object.
|
| */
|
| -v8Locale.__createSettingsOrDefault = function(settings, defaults) {
|
| +v8Locale.createSettingsOrDefault_ = function(settings, defaults) {
|
| if (!settings || typeof(settings) !== 'object' ) {
|
| return defaults;
|
| }
|
| @@ -236,17 +155,11 @@ v8Locale.__createSettingsOrDefault = function(settings, defaults) {
|
| settings[key] = defaults[key];
|
| }
|
| }
|
| - // Clean up settings.
|
| + // Clean up values, like trimming whitespace.
|
| for (var key in settings) {
|
| - // Trim whitespace.
|
| if (typeof(settings[key]) === "string") {
|
| settings[key] = settings[key].trim();
|
| }
|
| - // Remove all properties that are set to undefined/null. This allows
|
| - // derive method to remove a setting we don't need anymore.
|
| - if (!settings[key]) {
|
| - delete settings[key];
|
| - }
|
| }
|
|
|
| return settings;
|
| @@ -258,7 +171,7 @@ v8Locale.__createSettingsOrDefault = function(settings, defaults) {
|
| * @param {!Object} locale - user provided locale.
|
| * @returns {Object} - v8Locale object.
|
| */
|
| -v8Locale.__createLocaleOrDefault = function(locale) {
|
| +v8Locale.createLocaleOrDefault_ = function(locale) {
|
| if (!locale || !(locale instanceof v8Locale)) {
|
| return new v8Locale();
|
| } else {
|
|
|