<commit_before>(function () {
    'use strict';

    angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', 'ariaNgStorageService', function ($window, $location, $filter, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService, ariaNgStorageService) {
        var browserFeatures = (function () {
            var supportLocalStroage = ariaNgStorageService.isLocalStorageSupported();
            var supportCookies = ariaNgStorageService.isCookiesSupported();

            return {
                localStroage: supportLocalStroage,
                cookies: supportCookies
            };
        })();
        var browserSupportStorage = browserFeatures.localStroage || browserFeatures.cookies;
        var browserSupportAppCache = !!$window.applicationCache;
        var browserSupportMatchMedia = !!$window.matchMedia;
        var browserSupportDarkMode = browserSupportMatchMedia && $window.matchMedia('(prefers-color-scheme: dark)') && $window.matchMedia('(prefers-color-scheme: dark)').media !== 'not all';

        var onAppCacheUpdatedCallbacks = [];
        var onFirstVisitCallbacks = [];
        var firstVisitCallbackFired = false;
        var sessionSettings = {
            debugMode: false
        };

        if (browserSupportAppCache) {
            var appCache = $window.applicationCache;
            appCache.addEventListener('updateready', function (e) {
                for (var i = 0; i < onAppCacheUpdatedCallbacks.length; i++) {
                    var callback = onAppCacheUpdatedCallbacks[i];
                    callback();
                }
            }, false);
        }

        var fireFirstVisitEvent = function () {
            if (!browserSupportStorage) {
                return;
            }

            if (firstVisitCallbackFired || !angular.isArray(onFirstVisitCallbacks) || onFirstVisitCallbacks.length < 1) {
                return;
            }

            for (var i = 0; i < onFirstVisitCallbacks.length; i++) {
                var callback = onFirstVisitCallbacks[i];
                callback();
            }

            firstVisitCallbackFired = true;
        };

        var isInsecureProtocolDisabled = function () {
            var protocol = $location.protocol();

            return protocol === 'https';
        };

        var getLanguageNameFromAlias = function (alias) {
            for (var langName in ariaNgLanguages) {
                if (!ariaNgLanguages.hasOwnProperty(langName)) {
                    continue;
                }

                if (langName.toLowerCase() === alias.toLowerCase()) {
                    return langName;
                }

                var language = ariaNgLanguages[langName];
                var aliases = language.aliases;

                if (!angular.isArray(aliases) || aliases.length < 1) {
                    continue;
                }

                for (var i = 0; i < aliases.length; i++) {
                    if (aliases[i].toLowerCase() === alias.toLowerCase()) {
                        return langName;
                    }
                }
            }

            return null;
        };

        var getDefaultLanguage = function () {
            var browserLang = $window.navigator.browserLanguage ? $window.navigator.browserLanguage : $window.navigator.language;

            if (!browserLang) {
                ariaNgLogService.info('[ariaNgSettingService] cannot get browser language, use default language');
                return ariaNgDefaultOptions.language;
            }

            browserLang = browserLang.replace(/\-/g, '_');

            if (!ariaNgLanguages[browserLang]) {
                var languageName = getLanguageNameFromAlias(browserLang);

                if (languageName) {
                    browserLang = languageName;
                }
            }

            if (!ariaNgLanguages[browserLang] && browserLang.split('-').length > 1) { // maybe language-script-region
                const langParts = browserLang.split('-');
                browserLang = langParts[0] + '-' + langParts[1];

                if (!ariaNgLanguages[browserLang]) {
                    const languageName = getLanguageNameFromAlias(browserLang);

                    if (languageName) {
                        browserLang = languageName;
                    }
                }
            }
<commit_msg>fix code<commit_after>(function () {
    'use strict';

    angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', 'ariaNgStorageService', function ($window, $location, $filter, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService, ariaNgStorageService) {
        var browserFeatures = (function () {
            var supportLocalStroage = ariaNgStorageService.isLocalStorageSupported();
            var supportCookies = ariaNgStorageService.isCookiesSupported();

            return {
                localStroage: supportLocalStroage,
                cookies: supportCookies
            };
        })();
        var browserSupportStorage = browserFeatures.localStroage || browserFeatures.cookies;
        var browserSupportAppCache = !!$window.applicationCache;
        var browserSupportMatchMedia = !!$window.matchMedia;
        var browserSupportDarkMode = browserSupportMatchMedia && $window.matchMedia('(prefers-color-scheme: dark)') && $window.matchMedia('(prefers-color-scheme: dark)').media !== 'not all';

        var onAppCacheUpdatedCallbacks = [];
        var onFirstVisitCallbacks = [];
        var firstVisitCallbackFired = false;
        var sessionSettings = {
            debugMode: false
        };

        if (browserSupportAppCache) {
            var appCache = $window.applicationCache;
            appCache.addEventListener('updateready', function (e) {
                for (var i = 0; i < onAppCacheUpdatedCallbacks.length; i++) {
                    var callback = onAppCacheUpdatedCallbacks[i];
                    callback();
                }
            }, false);
        }

        var fireFirstVisitEvent = function () {
            if (!browserSupportStorage) {
                return;
            }

            if (firstVisitCallbackFired || !angular.isArray(onFirstVisitCallbacks) || onFirstVisitCallbacks.length < 1) {
                return;
            }

            for (var i = 0; i < onFirstVisitCallbacks.length; i++) {
                var callback = onFirstVisitCallbacks[i];
                callback();
            }

            firstVisitCallbackFired = true;
        };

        var isInsecureProtocolDisabled = function () {
            var protocol = $location.protocol();

            return protocol === 'https';
        };

        var getLanguageNameFromAlias = function (alias) {
            for (var langName in ariaNgLanguages) {
                if (!ariaNgLanguages.hasOwnProperty(langName)) {
                    continue;
                }

                if (langName.toLowerCase() === alias.toLowerCase()) {
                    return langName;
                }

                var language = ariaNgLanguages[langName];
                var aliases = language.aliases;

                if (!angular.isArray(aliases) || aliases.length < 1) {
                    continue;
                }

                for (var i = 0; i < aliases.length; i++) {
                    if (aliases[i].toLowerCase() === alias.toLowerCase()) {
                        return langName;
                    }
                }
            }

            return null;
        };

        var getDefaultLanguage = function () {
            var browserLang = $window.navigator.browserLanguage ? $window.navigator.browserLanguage : $window.navigator.language;

            if (!browserLang) {
                ariaNgLogService.info('[ariaNgSettingService] cannot get browser language, use default language');
                return ariaNgDefaultOptions.language;
            }

            browserLang = browserLang.replace(/\-/g, '_');

            if (!ariaNgLanguages[browserLang]) {
                var languageName = getLanguageNameFromAlias(browserLang);

                if (languageName) {
                    browserLang = languageName;
                }
            }

            if (!ariaNgLanguages[browserLang] && browserLang.split('-').length > 1) { // maybe language-script-region
                var langParts = browserLang.split('-');
                browserLang = langParts[0] + '-' + langParts[1];

                if (!ariaNgLanguages[browserLang]) {
                    var languageName = getLanguageNameFromAlias(browserLang);

                    if (languageName) {
                        browserLang = languageName;
                    }
                }
            }

{'fraction_non_alphanumeric': 0.1018671969948072, 'fraction_numerical': 0.0017677604684565242, 'mean_word_length': 1.805951642901426, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3511078', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2173, 'n_words': 433}