]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui3/build/widget/widget-locale.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / yui3 / build / widget / widget-locale.js
1 /*
2  Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3  Code licensed under the BSD License:
4  http://developer.yahoo.com/yui/license.html
5  version: 3.3.0
6  build: 3167
7  */
8 YUI.add('widget-locale',function(Y){var TRUE=true,LOCALE="locale",INIT_VALUE="initValue",HYPHEN="-",EMPTY_STR="",Widget=Y.Widget;Widget.ATTRS[LOCALE]={value:"en"};Widget.ATTRS.strings.lazyAdd=false;Y.mix(Widget.prototype,{_setStrings:function(strings,locale){var strs=this._strs;locale=locale.toLowerCase();if(!strs[locale]){strs[locale]={};}
9 Y.aggregate(strs[locale],strings,TRUE);return strs[locale];},_getStrings:function(locale){return this._strs[locale.toLowerCase()];},getStrings:function(locale){locale=(locale||this.get(LOCALE)).toLowerCase();var defLocale=this.getDefaultLocale().toLowerCase(),defStrs=this._getStrings(defLocale),strs=(defStrs)?Y.merge(defStrs):{},localeSegments=locale.split(HYPHEN),localeStrs,i,l,lookup;if(locale!==defLocale||localeSegments.length>1){lookup=EMPTY_STR;for(i=0,l=localeSegments.length;i<l;++i){lookup+=localeSegments[i];localeStrs=this._getStrings(lookup);if(localeStrs){Y.aggregate(strs,localeStrs,TRUE);}
10 lookup+=HYPHEN;}}
11 return strs;},getString:function(key,locale){locale=(locale||this.get(LOCALE)).toLowerCase();var defLocale=(this.getDefaultLocale()).toLowerCase(),strs=this._getStrings(defLocale)||{},str=strs[key],idx=locale.lastIndexOf(HYPHEN);if(locale!==defLocale||idx!=-1){do{strs=this._getStrings(locale);if(strs&&key in strs){str=strs[key];break;}
12 idx=locale.lastIndexOf(HYPHEN);if(idx!=-1){locale=locale.substring(0,idx);}}while(idx!=-1);}
13 return str;},getDefaultLocale:function(){return this._state.get(LOCALE,INIT_VALUE);},_strSetter:function(val){return this._setStrings(val,this.get(LOCALE));},_strGetter:function(val){return this._getStrings(this.get(LOCALE));}},true);},'3.3.0',{requires:['widget-base']});