Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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