1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('widget-locale', function (Y, NAME) {
5
* 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.
7
* @module widget-locale
8
* @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.
12
INIT_VALUE = "initValue",
19
* @deprecated Use Y.config.lang and Y.Intl externalization support
21
* The default locale for the widget. NOTE: Using get/set on the "strings" attribute will
22
* return/set strings for this locale.
26
Widget.ATTRS[LOCALE] = {
30
// Since strings support with locale needs the private _strs setup
31
Widget.ATTRS.strings.lazyAdd = false;
33
Y.mix(Widget.prototype, {
36
* Sets strings for a particular locale, merging with any existing
37
* strings which may already be defined for the locale.
41
* @param {Object} strings The hash of string key/values to set
42
* @param {Object} locale The locale for the string values being set
44
_setStrings : function(strings, locale) {
45
var strs = this._strs;
46
locale = locale.toLowerCase();
52
Y.aggregate(strs[locale], strings, TRUE);
57
* Returns the strings key/value hash for a paricular locale, without locale lookup applied.
61
* @param {Object} locale
63
_getStrings : function(locale) {
64
return this._strs[locale.toLowerCase()];
68
* Gets the entire strings hash for a particular locale, performing locale lookup.
70
* If no values of the key are defined for a particular locale the value for the
71
* default locale (in initial locale set for the class) is returned.
74
* @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
76
// TODO: Optimize/Cache. Clear cache on _setStrings call.
77
getStrings : function(locale) {
79
locale = (locale || this.get(LOCALE)).toLowerCase();
82
var defLocale = this.getDefaultLocale().toLowerCase(),
83
defStrs = this._getStrings(defLocale),
84
strs = (defStrs) ? Y.merge(defStrs) : {},
85
localeSegments = locale.split(HYPHEN),
90
// If locale is different than the default, or needs lookup support
91
if (locale !== defLocale || localeSegments.length > 1) {
93
for (i = 0, l = localeSegments.length; i < l; ++i) {
94
lookup += localeSegments[i];
97
localeStrs = this._getStrings(lookup);
99
Y.aggregate(strs, localeStrs, TRUE);
109
* Gets the string for a particular key, for a particular locale, performing locale lookup.
111
* If no values if defined for the key, for the given locale, the value for the
112
* default locale (in initial locale set for the class) is returned.
115
* @param {String} key The key.
116
* @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
118
getString : function(key, locale) {
120
locale = (locale || this.get(LOCALE)).toLowerCase();
123
var defLocale = (this.getDefaultLocale()).toLowerCase(),
124
strs = this._getStrings(defLocale) || {},
126
idx = locale.lastIndexOf(HYPHEN);
128
// If locale is different than the default, or needs lookup support
129
if (locale !== defLocale || idx != -1) {
132
strs = this._getStrings(locale);
133
if (strs && key in strs) {
137
idx = locale.lastIndexOf(HYPHEN);
138
// Chop of last locale segment
140
locale = locale.substring(0, idx);
150
* Returns the default locale for the widget (the locale value defined by the
151
* widget class, or provided by the user during construction).
153
* @method getDefaultLocale
154
* @return {String} The default locale for the widget
156
getDefaultLocale : function() {
157
return this._state.get(LOCALE, INIT_VALUE);
160
_strSetter : function(val) {
161
return this._setStrings(val, this.get(LOCALE));
164
_strGetter : function(val) {
165
return this._getStrings(this.get(LOCALE));
170
}, '3.9.1', {"requires": ["widget-base"]});