[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('intl-base', function (Y, NAME) { 9 10 /** 11 * The Intl utility provides a central location for managing sets of 12 * localized resources (strings and formatting patterns). 13 * 14 * @class Intl 15 * @uses EventTarget 16 * @static 17 */ 18 19 var SPLIT_REGEX = /[, ]/; 20 21 Y.mix(Y.namespace('Intl'), { 22 23 /** 24 * Returns the language among those available that 25 * best matches the preferred language list, using the Lookup 26 * algorithm of BCP 47. 27 * If none of the available languages meets the user's preferences, 28 * then "" is returned. 29 * Extended language ranges are not supported. 30 * 31 * @method lookupBestLang 32 * @param {String[] | String} preferredLanguages The list of preferred 33 * languages in descending preference order, represented as BCP 47 34 * language tags. A string array or a comma-separated list. 35 * @param {String[]} availableLanguages The list of languages 36 * that the application supports, represented as BCP 47 language 37 * tags. 38 * 39 * @return {String} The available language that best matches the 40 * preferred language list, or "". 41 * @since 3.1.0 42 */ 43 lookupBestLang: function(preferredLanguages, availableLanguages) { 44 45 var i, language, result, index; 46 47 // check whether the list of available languages contains language; 48 // if so return it 49 function scan(language) { 50 var i; 51 for (i = 0; i < availableLanguages.length; i += 1) { 52 if (language.toLowerCase() === 53 availableLanguages[i].toLowerCase()) { 54 return availableLanguages[i]; 55 } 56 } 57 } 58 59 if (Y.Lang.isString(preferredLanguages)) { 60 preferredLanguages = preferredLanguages.split(SPLIT_REGEX); 61 } 62 63 for (i = 0; i < preferredLanguages.length; i += 1) { 64 language = preferredLanguages[i]; 65 if (!language || language === '*') { 66 continue; 67 } 68 // check the fallback sequence for one language 69 while (language.length > 0) { 70 result = scan(language); 71 if (result) { 72 return result; 73 } else { 74 index = language.lastIndexOf('-'); 75 if (index >= 0) { 76 language = language.substring(0, index); 77 // one-character subtags get cut along with the 78 // following subtag 79 if (index >= 2 && language.charAt(index - 2) === '-') { 80 language = language.substring(0, index - 2); 81 } 82 } else { 83 // nothing available for this language 84 break; 85 } 86 } 87 } 88 } 89 90 return ''; 91 } 92 }); 93 94 95 }, '3.17.2', {"requires": ["yui-base"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |