<commit_before>
modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/format', 'core/store', 'core/event'], function (_, $, allsettings, langs, format, store, event) {

	var settings = _.extend({
			enabled: true,
			lang: 'en',
			useBrowserLang: true
		}, allsettings.l10n),

		defaultTranslations = {
			lang: 'english',
			details: 'details',
			list: "list",
			grid: "grid",
			icons: 'icons',
			name: 'Name',
			lastModified: 'Last modified',
			size: 'Size',
			parentDirectory: 'Parent Directory',
			empty: 'empty',
			folders: 'folders',
			files: 'files',
			download: 'download',
			noMatch: 'no match',
			dateFormat: 'YYYY-MM-DD HH:mm',
			filter: 'filter'
		},

		template = '<span id="langSelector">' +
						'<span class="lang">en</span> - <span class="l10n-lang">english</span>' +
						'<span class="langOptions"><ul/></span>' +
					'</span>',
		langOptionTemplate = '<li class="langOption"/>',

		storekey = 'h5ai.language',

		loaded = {
			en: _.extend({}, defaultTranslations)
		},
		currentLang = null,

		loadLanguage = function (lang, callback) {

			if (loaded[lang]) {

				callback(loaded[lang]);
			} else {

				$.ajax({
					url: allsettings.h5aiAbsHref + 'l10n/' + lang + '.json',
					dataType: 'json',
					success: function (json) {

						loaded[lang] = _.extend({}, defaultTranslations, json);
						callback(loaded[lang]);
					},
					error: function () {

						loaded[lang] = _.extend({}, defaultTranslations);
						callback(loaded[lang]);
					}
				});
			}
		},

		localize = function (langs, lang, useBrowserLang) {

			var storedLang = store.get(storekey);

			if (langs[storedLang]) {
				lang = storedLang;
			} else if (useBrowserLang) {
				var browserLang = navigator.language || navigator.browserLanguage;
				if (browserLang) {
					if (langs[browserLang]) {
						lang = browserLang;
					} else if (browserLang.length > 2 && langs[browserLang.substr(0, 2)]) {
						lang = browserLang.substr(0, 2);
					}
				}
			}

			if (!langs[lang]) {
				lang = 'en';
			}

			loadLanguage(lang, function (currentLang) {

				$.each(currentLang, function (key, value) {
					$('.l10n-' + key).text(value);
				});
				$('.lang').text(lang);
				$('.langOption').removeClass('current');
				$('.langOption.' + lang).addClass('current');

				format.setDefaultDateFormat(currentLang.dateFormat);

				$('#extended .entry .date').each(function () {

					var $this = $(this);

					$this.text(format.formatDate($this.data('time')));
				});

				$('#filter input').attr('placeholder', currentLang.filter);
			});
		},

		initLangSelector = function (langs) {

			var $langSelector = $(template).appendTo('#bottombar .right'),
				$langOptions = $langSelector.find('.langOptions'),
				$ul = $langOptions.find('ul'),
				sortedLangsKeys = [];

			$.each(langs, function (lang) {
				sortedLangsKeys.push(lang);
			});
			sortedLangsKeys.sort();

			$.each(sortedLangsKeys, function (idx, lang) {
				$(langOptionTemplate)
					.addClass(lang)
					.text(lang + ' - ' + (_.isString(langs[lang]) ? langs[lang] : langs[lang].lang))
					.appendTo($ul)
					.click(function () {
						store.put(storekey, lang);
						localize(langs, lang, false);
					});
			});
			$langOptions
				.append($ul)
				.scrollpanel();

			$langSelector.hover(
				function () {
					$langOptions
						.css('top', '-' + $langOptions.outerHeight() + 'px')
						.stop(true, true)
						.fadeIn();

					// needs to be updated twice for initial fade in rendering :/
					$langOptions.scrollpanel('update').scrollpanel('update');
				},
				function () {
					$langOptions
						.stop(true, true)
						.fadeOut();
				}
			);
		},

		init = function () {

			if (!settings.enabled) {
				return;
			}

			initLangSelector(langs);

			event.sub('ready', function () {

				localize(langs, settings.lang, settings.useBrowserLang);
			});
		};

	init();
});
<commit_msg>Fixes l10n in case it is disabled.<commit_after>
modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/format', 'core/store', 'core/event'], function (_, $, allsettings, langs, format, store, event) {

	var settings = _.extend({
			enabled: true,
			lang: 'en',
			useBrowserLang: true
		}, allsettings.l10n),

		defaultTranslations = {
			isoCode: 'en',
			lang: 'english',
			details: 'details',
			list: "list",
			grid: "grid",
			icons: 'icons',
			name: 'Name',
			lastModified: 'Last modified',
			size: 'Size',
			parentDirectory: 'Parent Directory',
			empty: 'empty',
			folders: 'folders',
			files: 'files',
			download: 'download',
			noMatch: 'no match',
			dateFormat: 'YYYY-MM-DD HH:mm',
			filter: 'filter'
		},

		template = '<span id="langSelector">' +
						'<span class="lang">en</span> - <span class="l10n-lang">english</span>' +
						'<span class="langOptions"><ul/></span>' +
					'</span>',
		langOptionTemplate = '<li class="langOption"/>',

		storekey = 'h5ai.language',

		loaded = {
			en: _.extend({}, defaultTranslations)
		},
		currentLang = loaded.en,

		update = function (lang) {

			if (lang) {
				currentLang = lang;
			}

			$.each(currentLang, function (key, value) {
				$('.l10n-' + key).text(value);
			});
			$('.lang').text(currentLang.isoCode);
			$('.langOption').removeClass('current');
			$('.langOption.' + currentLang.isoCode).addClass('current');

			format.setDefaultDateFormat(currentLang.dateFormat);

			$('#extended .entry .date').each(function () {

				var $this = $(this);

				$this.text(format.formatDate($this.data('time')));
			});

			$('#filter input').attr('placeholder', currentLang.filter);
		},

		loadLanguage = function (isoCode, callback) {

			if (loaded[isoCode]) {

				callback(loaded[isoCode]);
			} else {

				$.ajax({
					url: allsettings.h5aiAbsHref + 'l10n/' + isoCode + '.json',
					dataType: 'json',
					success: function (json) {

						loaded[isoCode] = _.extend({}, defaultTranslations, json, {isoCode: isoCode});
						callback(loaded[isoCode]);
					},
					error: function () {

						loaded[isoCode] = _.extend({}, defaultTranslations, {isoCode: isoCode});
						callback(loaded[isoCode]);
					}
				});
			}
		},

		localize = function (langs, isoCode, useBrowserLang) {

			var storedIsoCode = store.get(storekey);

			if (langs[storedIsoCode]) {
				isoCode = storedIsoCode;
			} else if (useBrowserLang) {
				var browserLang = navigator.language || navigator.browserLanguage;
				if (browserLang) {
					if (langs[browserLang]) {
						isoCode = browserLang;
					} else if (browserLang.length > 2 && langs[browserLang.substr(0, 2)]) {
						isoCode = browserLang.substr(0, 2);
					}
				}
			}

			if (!langs[isoCode]) {
				isoCode = 'en';
			}

			loadLanguage(isoCode, update);
		},

		initLangSelector = function (langs) {

			var $langSelector = $(template).appendTo('#bottombar .right'),
				$langOptions = $langSelector.find('.langOptions'),
				$ul = $langOptions.find('ul'),
				isoCodes = [];

			$.each(langs, function (isoCode) {
				isoCodes.push(isoCode);
			});
			isoCodes.sort();

			$.each(isoCodes, function (idx, isoCode) {
				$(langOptionTemplate)
					.addClass(isoCode)
					.text(isoCode + ' - ' + (_.isString(langs[isoCode]) ? langs[isoCode] : langs[isoCode].lang))
					.appendTo($ul)
					.click(function () {
						store.put(storekey, isoCode);
						localize(langs, isoCode, false);
					});
			});
			$langOptions
				.append($ul)
				.scrollpanel();

			$langSelector.hover(
				function () {
					$langOptions
						.css('top', '-' + $langOptions.outerHeight() + 'px')
						.stop(true, true)
						.fadeIn();

					// needs to be updated twice for initial fade in rendering :/
					$langOptions.scrollpanel('update').scrollpanel('update');
				},
				function () {
					$langOptions
						.stop(true, true)
						.fadeOut();
				}
			);
		},

		init = function () {

			if (!settings.enabled) {
				event.sub('ready', function () { update(); });
				return;
			}

			initLangSelector(langs);

			event.sub('ready', function () {

				localize(langs, settings.lang, settings.useBrowserLang);
			});
		};

	init();
});

{'fraction_non_alphanumeric': 0.1847181008902077, 'fraction_numerical': 0.004451038575667656, 'mean_word_length': 3.0445, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '638771', 'n_tokens_mistral': 3491, 'n_tokens_neox': 2680, 'n_words': 515}