src/static/js/Intl.js
function /* 9.2.5 */$$core$$ResolveLocale (availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) {
        if (availableLocales.length === 0) {
            throw new ReferenceError('No locale data has been provided for this object yet.');
        }

        // The following steps are taken:
        var
            // 1. Let matcher be the value of options.[[localeMatcher]].
            matcher = options['[[localeMatcher]]'];

        // 2. If matcher is "lookup", then
        if (matcher === 'lookup')
            var
                // a. Let r be the result of calling the LookupMatcher abstract operation
                //    (defined in 9.2.3) with arguments availableLocales and
                //    requestedLocales.
                r = $$core$$LookupMatcher(availableLocales, requestedLocales);

        // 3. Else
        else
            var
                // a. Let r be the result of calling the BestFitMatcher abstract
                //    operation (defined in 9.2.4) with arguments availableLocales and
                //    requestedLocales.
                r = $$core$$BestFitMatcher(availableLocales, requestedLocales);

        var
            // 4. Let foundLocale be the value of r.[[locale]].
            foundLocale = r['[[locale]]'];

        // 5. If r has an [[extension]] field, then
        if ($$core$$hop.call(r, '[[extension]]'))
            var
                // a. Let extension be the value of r.[[extension]].
                extension = r['[[extension]]'],
                // b. Let extensionIndex be the value of r.[[extensionIndex]].
                extensionIndex = r['[[extensionIndex]]'],
                // c. Let split be the standard built-in function object defined in ES5,
                //    15.5.4.14.
                split = String.prototype.split,
                // d. Let extensionSubtags be the result of calling the [[Call]] internal
                //    method of split with extension as the this value and an argument
                //    list containing the single item "-".
                extensionSubtags = split.call(extension, '-'),
                // e. Let extensionSubtagsLength be the result of calling the [[Get]]
                //    internal method of extensionSubtags with argument "length".
                extensionSubtagsLength = extensionSubtags.length;

        var
            // 6. Let result be a new Record.
            result = new $$core$$Record();

        // 7. Set result.[[dataLocale]] to foundLocale.
        result['[[dataLocale]]'] = foundLocale;

        var
            // 8. Let supportedExtension be "-u".
            supportedExtension = '-u',
            // 9. Let i be 0.
            i = 0,
            // 10. Let len be the result of calling the [[Get]] internal method of
            //     relevantExtensionKeys with argument "length".
            len = relevantExtensionKeys.length;

        // 11 Repeat while i < len:
        while (i < len) {
            var
                // a. Let key be the result of calling the [[Get]] internal method of
                //    relevantExtensionKeys with argument ToString(i).
                key = relevantExtensionKeys[i],
                // b. Let foundLocaleData be the result of calling the [[Get]] internal
                //    method of localeData with the argument foundLocale.
                foundLocaleData = localeData[foundLocale],
                // c. Let keyLocaleData be the result of calling the [[Get]] internal
                //    method of foundLocaleData with the argument key.
                keyLocaleData = foundLocaleData[key],
                // d. Let value be the result of calling the [[Get]] internal method of
                //    keyLocaleData with argument "0".
                value = keyLocaleData['0'],
                // e. Let supportedExtensionAddition be "".
                supportedExtensionAddition = '',
                // f. Let indexOf be the standard built-in function object defined in
                //    ES5, 15.4.4.14.
                indexOf = $$core$$arrIndexOf;

            // g. If extensionSubtags is not undefined, then
            if (extensionSubtags !== undefined) {
                var
                    // i. Let keyPos be the result of calling the [[Call]] internal
                    //    method of indexOf with extensionSubtags as the this value and
                    // an argument list containing the single item key.
                    keyPos = indexOf.call(extensionSubtags, key);

                // ii. If keyPos ≠ -1, then
                if (keyPos !== -1) {
                    // 1. If keyPos + 1 < extensionSubtagsLength and the length of the
                    //    result of calling the [[Get]] internal method of
                    //    extensionSubtags with argument ToString(keyPos +1) is greater
                    //    than 2, then
                    if (keyPos + 1 < extensionSubtagsLength
                            && extensionSubtags[keyPos + 1].length > 2) {
                        var
                            // a. Let requestedValue be the result of calling the [[Get]]
                            //    internal method of extensionSubtags with argument
                            //    ToString(keyPos + 1).
                            requestedValue = extensionSubtags[keyPos + 1],
                            // b. Let valuePos be the result of calling the [[Call]]
                            //    internal method of indexOf with keyLocaleData as the
                            //    this value and an argument list containing the single
                            //    item requestedValue.
                            valuePos = indexOf.call(keyLocaleData, requestedValue);

                        // c. If valuePos ≠ -1, then
                        if (valuePos !== -1)
                            var
                                // i. Let value be requestedValue.
                                value = requestedValue,
                                // ii. Let supportedExtensionAddition be the
                                //     concatenation of "-", key, "-", and value.
                                supportedExtensionAddition = '-' + key + '-' + value;
                    }
                    // 2. Else
                    else {
                        var
                            // a. Let valuePos be the result of calling the [[Call]]
                            // internal method of indexOf with keyLocaleData as the this
                            // value and an argument list containing the single item
                            // "true".
                            valuePos = indexOf(keyLocaleData, 'true');

                        // b. If valuePos ≠ -1, then
                        if (valuePos !== -1)
                            var
                                // i. Let value be "true".
                                value = 'true';
                    }
                }
            }
            // h. If options has a field [[<key>]], then
            if ($$core$$hop.call(options, '[[' + key + ']]')) {
                var
                    // i. Let optionsValue be the value of options.[[<key>]].
                    optionsValue = options['[[' + key + ']]'];

                // ii. If the result of calling the [[Call]] internal method of indexOf
                //     with keyLocaleData as the this value and an argument list
                //     containing the single item optionsValue is not -1, then
                if (indexOf.call(keyLocaleData, optionsValue) !== -1) {
                    // 1. If optionsValue is not equal to value, then
                    if (optionsValue !== value) {
                        // a. Let value be optionsValue.
                        value = optionsValue;
                        // b. Let supportedExtensionAddition be "".
                        supportedExtensionAddition = '';
                    }
                }
            }
            // i. Set result.[[<key>]] to value.
            result['[[' + key + ']]'] = value;

            // j. Append supportedExtensionAddition to supportedExtension.
            supportedExtension += supportedExtensionAddition;

            // k. Increase i by 1.
            i++;
        }
        // 12. If the length of supportedExtension is greater than 2, then
        if (supportedExtension.length > 2) {
            var
                // a. Let preExtension be the substring of foundLocale from position 0,
                //    inclusive, to position extensionIndex, exclusive.
                preExtension = foundLocale.substring(0, extensionIndex),
                // b. Let postExtension be the substring of foundLocale from position
                //    extensionIndex to the end of the string.
                postExtension = foundLocale.substring(extensionIndex),
                // c. Let foundLocale be the concatenation of preExtension,
                //    supportedExtension, and postExtension.
                foundLocale = preExtension + supportedExtension + postExtension;
        }
        // 13. Set result.[[locale]] to foundLocale.
        result['[[locale]]'] = foundLocale;

        // 14. Return result.
        return result;
    }
function /* 9.2.5 */$$core$$ResolveLocale (availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) {
        if (availableLocales.length === 0) {
            throw new ReferenceError('No locale data has been provided for this object yet.');
        }

        // The following steps are taken:
        var
            // 1. Let matcher be the value of options.[[localeMatcher]].
            matcher = options['[[localeMatcher]]'];

        // 2. If matcher is "lookup", then
        if (matcher === 'lookup')
            var
                // a. Let r be the result of calling the LookupMatcher abstract operation
                //    (defined in 9.2.3) with arguments availableLocales and
                //    requestedLocales.
                r = $$core$$LookupMatcher(availableLocales, requestedLocales);

        // 3. Else
        else
            var
                // a. Let r be the result of calling the BestFitMatcher abstract
                //    operation (defined in 9.2.4) with arguments availableLocales and
                //    requestedLocales.
                r = $$core$$BestFitMatcher(availableLocales, requestedLocales);

        var
            // 4. Let foundLocale be the value of r.[[locale]].
            foundLocale = r['[[locale]]'];

        // 5. If r has an [[extension]] field, then
        if ($$core$$hop.call(r, '[[extension]]'))
            var
                // a. Let extension be the value of r.[[extension]].
                extension = r['[[extension]]'],
                // b. Let extensionIndex be the value of r.[[extensionIndex]].
                extensionIndex = r['[[extensionIndex]]'],
                // c. Let split be the standard built-in function object defined in ES5,
                //    15.5.4.14.
                split = String.prototype.split,
                // d. Let extensionSubtags be the result of calling the [[Call]] internal
                //    method of split with extension as the this value and an argument
                //    list containing the single item "-".
                extensionSubtags = split.call(extension, '-'),
                // e. Let extensionSubtagsLength be the result of calling the [[Get]]
                //    internal method of extensionSubtags with argument "length".
                extensionSubtagsLength = extensionSubtags.length;

        var
            // 6. Let result be a new Record.
            result = new $$core$$Record();

        // 7. Set result.[[dataLocale]] to foundLocale.
        result['[[dataLocale]]'] = foundLocale;

        var
            // 8. Let supportedExtension be "-u".
            supportedExtension = '-u',
            // 9. Let i be 0.
            i = 0,
            // 10. Let len be the result of calling the [[Get]] internal method of
            //     relevantExtensionKeys with argument "length".
            len = relevantExtensionKeys.length;

        // 11 Repeat while i < len:
        while (i < len) {
            var
                // a. Let key be the result of calling the [[Get]] internal method of
                //    relevantExtensionKeys with argument ToString(i).
                key = relevantExtensionKeys[i],
                // b. Let foundLocaleData be the result of calling the [[Get]] internal
                //    method of localeData with the argument foundLocale.
                foundLocaleData = localeData[foundLocale],
                // c. Let keyLocaleData be the result of calling the [[Get]] internal
                //    method of foundLocaleData with the argument key.
                keyLocaleData = foundLocaleData[key],
                // d. Let value be the result of calling the [[Get]] internal method of
                //    keyLocaleData with argument "0".
                value = keyLocaleData['0'],
                // e. Let supportedExtensionAddition be "".
                supportedExtensionAddition = '',
                // f. Let indexOf be the standard built-in function object defined in
                //    ES5, 15.4.4.14.
                indexOf = $$core$$arrIndexOf;

            // g. If extensionSubtags is not undefined, then
            if (extensionSubtags !== undefined) {
                var
                    // i. Let keyPos be the result of calling the [[Call]] internal
                    //    method of indexOf with extensionSubtags as the this value and
                    // an argument list containing the single item key.
                    keyPos = indexOf.call(extensionSubtags, key);

                // ii. If keyPos ≠ -1, then
                if (keyPos !== -1) {
                    // 1. If keyPos + 1 < extensionSubtagsLength and the length of the
                    //    result of calling the [[Get]] internal method of
                    //    extensionSubtags with argument ToString(keyPos +1) is greater
                    //    than 2, then
                    if (keyPos + 1 < extensionSubtagsLength
                            && extensionSubtags[keyPos + 1].length > 2) {
                        var
                            // a. Let requestedValue be the result of calling the [[Get]]
                            //    internal method of extensionSubtags with argument
                            //    ToString(keyPos + 1).
                            requestedValue = extensionSubtags[keyPos + 1],
                            // b. Let valuePos be the result of calling the [[Call]]
                            //    internal method of indexOf with keyLocaleData as the
                            //    this value and an argument list containing the single
                            //    item requestedValue.
                            valuePos = indexOf.call(keyLocaleData, requestedValue);

                        // c. If valuePos ≠ -1, then
                        if (valuePos !== -1)
                            var
                                // i. Let value be requestedValue.
                                value = requestedValue,
                                // ii. Let supportedExtensionAddition be the
                                //     concatenation of "-", key, "-", and value.
                                supportedExtensionAddition = '-' + key + '-' + value;
                    }
                    // 2. Else
                    else {
                        var
                            // a. Let valuePos be the result of calling the [[Call]]
                            // internal method of indexOf with keyLocaleData as the this
                            // value and an argument list containing the single item
                            // "true".
                            valuePos = indexOf(keyLocaleData, 'true');

                        // b. If valuePos ≠ -1, then
                        if (valuePos !== -1)
                            var
                                // i. Let value be "true".
                                value = 'true';
                    }
                }
            }
            // h. If options has a field [[<key>]], then
            if ($$core$$hop.call(options, '[[' + key + ']]')) {
                var
                    // i. Let optionsValue be the value of options.[[<key>]].
                    optionsValue = options['[[' + key + ']]'];

                // ii. If the result of calling the [[Call]] internal method of indexOf
                //     with keyLocaleData as the this value and an argument list
                //     containing the single item optionsValue is not -1, then
                if (indexOf.call(keyLocaleData, optionsValue) !== -1) {
                    // 1. If optionsValue is not equal to value, then
                    if (optionsValue !== value) {
                        // a. Let value be optionsValue.
                        value = optionsValue;
                        // b. Let supportedExtensionAddition be "".
                        supportedExtensionAddition = '';
                    }
                }
            }
            // i. Set result.[[<key>]] to value.
            result['[[' + key + ']]'] = value;

            // j. Append supportedExtensionAddition to supportedExtension.
            supportedExtension += supportedExtensionAddition;

            // k. Increase i by 1.
            i++;
        }
        // 12. If the length of supportedExtension is greater than 2, then
        if (supportedExtension.length > 2) {
            var
                // a. Let preExtension be the substring of foundLocale from position 0,
                //    inclusive, to position extensionIndex, exclusive.
                preExtension = foundLocale.substring(0, extensionIndex),
                // b. Let postExtension be the substring of foundLocale from position
                //    extensionIndex to the end of the string.
                postExtension = foundLocale.substring(extensionIndex),
                // c. Let foundLocale be the concatenation of preExtension,
                //    supportedExtension, and postExtension.
                foundLocale = preExtension + supportedExtension + postExtension;
        }
        // 13. Set result.[[locale]] to foundLocale.
        result['[[locale]]'] = foundLocale;

        // 14. Return result.
        return result;
    }
function /* 9.2.5 */ $$core$$ResolveLocale ( availableLocales , requestedLocales , options , relevantExtensionKeys , localeData ) { if ( availableLocales . length === 0 ) { throw new ReferenceError ( 'No locale data has been provided for this object yet.' ) ; } // The following steps are taken: var // 1. Let matcher be the value of options.[[localeMatcher]]. matcher = options [ '[[localeMatcher]]' ] ; // 2. If matcher is "lookup", then if ( matcher === 'lookup' ) var // a. Let r be the result of calling the LookupMatcher abstract operation //    (defined in 9.2.3) with arguments availableLocales and //    requestedLocales. r = $$core$$LookupMatcher ( availableLocales , requestedLocales ) ; // 3. Else else var // a. Let r be the result of calling the BestFitMatcher abstract //    operation (defined in 9.2.4) with arguments availableLocales and //    requestedLocales. r = $$core$$BestFitMatcher ( availableLocales , requestedLocales ) ; var // 4. Let foundLocale be the value of r.[[locale]]. foundLocale = r [ '[[locale]]' ] ; // 5. If r has an [[extension]] field, then if ( $$core$$hop . call ( r , '[[extension]]' ) ) var // a. Let extension be the value of r.[[extension]]. extension = r [ '[[extension]]' ] , // b. Let extensionIndex be the value of r.[[extensionIndex]]. extensionIndex = r [ '[[extensionIndex]]' ] , // c. Let split be the standard built-in function object defined in ES5, //    15.5.4.14. split = String . prototype . split , // d. Let extensionSubtags be the result of calling the [[Call]] internal //    method of split with extension as the this value and an argument //    list containing the single item "-". extensionSubtags = split . call ( extension , '-' ) , // e. Let extensionSubtagsLength be the result of calling the [[Get]] //    internal method of extensionSubtags with argument "length". extensionSubtagsLength = extensionSubtags . length ; var // 6. Let result be a new Record. result = new $$core$$Record ( ) ; // 7. Set result.[[dataLocale]] to foundLocale. result [ '[[dataLocale]]' ] = foundLocale ; var // 8. Let supportedExtension be "-u". supportedExtension = '-u' , // 9. Let i be 0. i = 0 , // 10. Let len be the result of calling the [[Get]] internal method of //     relevantExtensionKeys with argument "length". len = relevantExtensionKeys . length ; // 11 Repeat while i < len: while ( i < len ) { var // a. Let key be the result of calling the [[Get]] internal method of //    relevantExtensionKeys with argument ToString(i). key = relevantExtensionKeys [ i ] , // b. Let foundLocaleData be the result of calling the [[Get]] internal //    method of localeData with the argument foundLocale. foundLocaleData = localeData [ foundLocale ] , // c. Let keyLocaleData be the result of calling the [[Get]] internal //    method of foundLocaleData with the argument key. keyLocaleData = foundLocaleData [ key ] , // d. Let value be the result of calling the [[Get]] internal method of //    keyLocaleData with argument "0". value = keyLocaleData [ '0' ] , // e. Let supportedExtensionAddition be "". supportedExtensionAddition = '' , // f. Let indexOf be the standard built-in function object defined in //    ES5, 15.4.4.14. indexOf = $$core$$arrIndexOf ; // g. If extensionSubtags is not undefined, then if ( extensionSubtags !== undefined ) { var // i. Let keyPos be the result of calling the [[Call]] internal //    method of indexOf with extensionSubtags as the this value and // an argument list containing the single item key. keyPos = indexOf . call ( extensionSubtags , key ) ; // ii. If keyPos ≠ -1, then if ( keyPos !== - 1 ) { // 1. If keyPos + 1 < extensionSubtagsLength and the length of the //    result of calling the [[Get]] internal method of //    extensionSubtags with argument ToString(keyPos +1) is greater //    than 2, then if ( keyPos + 1 < extensionSubtagsLength && extensionSubtags [ keyPos + 1 ] . length > 2 ) { var // a. Let requestedValue be the result of calling the [[Get]] //    internal method of extensionSubtags with argument //    ToString(keyPos + 1). requestedValue = extensionSubtags [ keyPos + 1 ] , // b. Let valuePos be the result of calling the [[Call]] //    internal method of indexOf with keyLocaleData as the //    this value and an argument list containing the single //    item requestedValue. valuePos = indexOf . call ( keyLocaleData , requestedValue ) ; // c. If valuePos ≠ -1, then if ( valuePos !== - 1 ) var // i. Let value be requestedValue. value = requestedValue , // ii. Let supportedExtensionAddition be the //     concatenation of "-", key, "-", and value. supportedExtensionAddition = '-' + key + '-' + value ; } // 2. Else else { var // a. Let valuePos be the result of calling the [[Call]] // internal method of indexOf with keyLocaleData as the this // value and an argument list containing the single item // "true". valuePos = indexOf ( keyLocaleData , 'true' ) ; // b. If valuePos ≠ -1, then if ( valuePos !== - 1 ) var // i. Let value be "true". value = 'true' ; } } } // h. If options has a field [[<key>]], then if ( $$core$$hop . call ( options , '[[' + key + ']]' ) ) { var // i. Let optionsValue be the value of options.[[<key>]]. optionsValue = options [ '[[' + key + ']]' ] ; // ii. If the result of calling the [[Call]] internal method of indexOf //     with keyLocaleData as the this value and an argument list //     containing the single item optionsValue is not -1, then if ( indexOf . call ( keyLocaleData , optionsValue ) !== - 1 ) { // 1. If optionsValue is not equal to value, then if ( optionsValue !== value ) { // a. Let value be optionsValue. value = optionsValue ; // b. Let supportedExtensionAddition be "". supportedExtensionAddition = '' ; } } } // i. Set result.[[<key>]] to value. result [ '[[' + key + ']]' ] = value ; // j. Append supportedExtensionAddition to supportedExtension. supportedExtension += supportedExtensionAddition ; // k. Increase i by 1. i ++ ; } // 12. If the length of supportedExtension is greater than 2, then if ( supportedExtension . length > 2 ) { var // a. Let preExtension be the substring of foundLocale from position 0, //    inclusive, to position extensionIndex, exclusive. preExtension = foundLocale . substring ( 0 , extensionIndex ) , // b. Let postExtension be the substring of foundLocale from position //    extensionIndex to the end of the string. postExtension = foundLocale . substring ( extensionIndex ) , // c. Let foundLocale be the concatenation of preExtension, //    supportedExtension, and postExtension. foundLocale = preExtension + supportedExtension + postExtension ; } // 13. Set result.[[locale]] to foundLocale. result [ '[[locale]]' ] = foundLocale ; // 14. Return result. return result ; }
The ResolveLocale abstract operation compares a BCP 47 language priority list
requestedLocales against the locales in availableLocales and determines the
best available language to meet the request. availableLocales and
requestedLocales must be provided as List values, options as a Record.
The ResolveLocale abstract operation compares a BCP 47 language priority list requestedLocales against the locales in availableLocales and determines the best available language to meet the request . availableLocales and requestedLocales must be provided as List values options as a Record .