76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Provides string support for widget with BCP 47 language tag lookup. This module has been deprecated. It's replaced by the "intl" module which provides generic internationalization and BCP 47 language tag support with externalization.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module widget-locale
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @deprecated This module has been deprecated. It's replaced by the "intl" module which provides generic internationalization and BCP 47 language tag support with externalization.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @attribute locale
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @deprecated Use Y.config.lang and Y.Intl externalization support
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @description
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The default locale for the widget. NOTE: Using get/set on the "strings" attribute will
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * return/set strings for this locale.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default "en"
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// Since strings support with locale needs the private _strs setup
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Sets strings for a particular locale, merging with any existing
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * strings which may already be defined for the locale.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _setStrings
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} strings The hash of string key/values to set
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} locale The locale for the string values being set
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns the strings key/value hash for a paricular locale, without locale lookup applied.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _getStrings
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} locale
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Gets the entire strings hash for a particular locale, performing locale lookup.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * If no values of the key are defined for a particular locale the value for the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * default locale (in initial locale set for the class) is returned.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method getStrings
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: Optimize/Cache. Clear cache on _setStrings call.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass locale = (locale || this.get(LOCALE)).toLowerCase();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log("getStrings: For " + locale, "info", "widget");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var defLocale = this.getDefaultLocale().toLowerCase(),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // If locale is different than the default, or needs lookup support
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (locale !== defLocale || localeSegments.length > 1) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass for (i = 0, l = localeSegments.length; i < l; ++i) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log("getStrings: Merging in strings from: " + lookup, "info", "widget");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Gets the string for a particular key, for a particular locale, performing locale lookup.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * If no values if defined for the key, for the given locale, the value for the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * default locale (in initial locale set for the class) is returned.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method getString
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} key The key.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass locale = (locale || this.get(LOCALE)).toLowerCase();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log("getString: For " + locale, "info", "widget");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var defLocale = (this.getDefaultLocale()).toLowerCase(),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // If locale is different than the default, or needs lookup support
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log("getString: Performing lookup for: " + locale, "info", "widget");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Chop of last locale segment
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns the default locale for the widget (the locale value defined by the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * widget class, or provided by the user during construction).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method getDefaultLocale
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {String} The default locale for the widget