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

	var PROJECTS_PREFIX = './projects/';
	var PROJECTS_JSON_SUFFIX = '.json';
	var PROJECTS_TXT_SUFFIX = '.txt';
	var PROJECT_TEMPLATE = "\
		<article class='6u 12u$(xsmall) work-item'>\
			<a href='{link}' data-poptrox='{poptroxData}' class='image fit thumb' id='{id}'><img src='images/thumbs/{id}.jpg' alt='' /></a>\
			<h3>{title}</h3>\
			<p>{short_description}</p>\
		</article>\
		";
	var CAPTION_TEMPLATE = "\
		<h3>{title}</h3>\
		<div class='tags'>{tags}</div>\
		<p>{long_description}</p>\
		";
	var ANIMATION_DURATION = 750;

	var settings = {
		"language": "fr",
		"possibleLanguages": ["fr", "en"]
	};

	var projects = {}

	var nbProjects = 0;

	var nbRequestToComeBack = 0;

	// Detects browser language and save it
	var detectBrowserLanguage = function () {
		settings.language = (navigator.language || navigator.userLanguage) != "fr" ? "en" : "fr";
		// console.log(settings.language);
	}

	// Takes content.js info and fill the blanks
	var fillContent = function () {
		
		$.each(info, function(index, value) {
			// console.log(index);
			$(index).html(value[settings.language]);
		});
	}

	// Donwloads all the projects
	var getProjects = function (callback) {
		fileExist(++nbProjects, function(){
			// console.log("Call callback");
			// callback();
		}.bind(callback),
		function(data){
			// Success callback
			loadProject(data, callback);
			// console.log("Found " + nbProjects + " projects");
			getProjects(callback);
		}.bind(callback))
	}

	var loadProject = function(data, callback) {
		var id = nbProjects;
		projects[id] = data;

		for (var i = settings.possibleLanguages.length - 1; i >= 0; i--) {
			var lang = settings.possibleLanguages[i];
			var targetUrl = PROJECTS_PREFIX + nbProjects + "." + lang + PROJECTS_TXT_SUFFIX;
			// console.log(targetUrl);
			nbRequestToComeBack++;
			$.ajax({
				url: targetUrl,
				dataType: "text",
				error: function(jqXHR, textStatus, errorThrown ){
					// If we don't find the page, log it and don't block
					console.warn("Coudn't find post " + id + " in " + lang);
					console.warn(textStatus);
					nbRequestToComeBack--;
				}.bind(id, lang),
				success: function(l, data, textStatus){
					nbRequestToComeBack--;
					// console.log("got " + id + " in " + l);
					// console.log(data);
					// console.log(l);
					projects[id][l].long_description = data;
					if (nbRequestToComeBack == 0) {
						callback();
					}
				}.bind(id, lang)
			});
		}
		// console.log(projects[nbProjects]);
	}

	// Test if a file exist and execute a callback according to the result
	var fileExist = function (idx, errorCallback, successCallback){
		var ret;

		$.ajax({
			url: PROJECTS_PREFIX + idx + PROJECTS_JSON_SUFFIX,
			dataType: "json",
			error: errorCallback,
			success: successCallback
		});
	}

	// Fills the project part
	var fillProjects = function () {
		$("#projects").html("");

		for (var i = nbProjects - 1 ; i > 0 ; i--) {
			var txt = PROJECT_TEMPLATE;
			console.log(projects[i].media.type == "image");
			// Set media type
			if (projects[i].media.type == "image") {
				txt = txt.replace("{link}", "images/fulls/{id}.jpg");
				txt = txt.replace("data-poptrox='{poptroxData}' ", "");
			} else {
				txt = txt.replace("{poptroxData}", projects[i].media.type);
				txt = txt.replace("{link}", projects[i].media.content);
			}
			
			// Set div to left of right
			if (i%2==0) {
				txt = txt.replace("6u", "6u$");
			}

			// Fill content of the project
			var content = projects[i][settings.language];
			// id
			txt = txt.replace(new RegExp("{id}", 'g'), i);
			// other
			$.each(projects[i][settings.language], function(index, value) {
				txt = txt.replace(new RegExp("{" + index + "}", 'g'), value);
			});
			console.log(txt);
			
			$("#projects").append(txt);
		}

		$('#two').poptrox({
			// caption: function($a) { return $a.next('div').html(); },
			caption: fillCaption,
			overlayColor: '#2c2c2c',
			overlayOpacity: 0.85,
			popupCloserText: '',
			popupLoaderText: '',
			selector: '.work-item a.image',
			usePopupCaption: true,
			usePopupDefaultStyling: false,
			usePopupEasyClose: false,
			usePopupNav: true,
			windowMargin: (skel.breakpoint('small').active ? 0 : 50)
			// onPopupOpen: fillProjectContent
		});
	}

	var fillCaption = function (a) {
		
		var i = a[0].id;

		var txt = CAPTION_TEMPLATE;
		var content = projects[i][settings.language];

		// Title
		txt = txt.replace("{title}", content.title);
		// Tags
		var tags = content.tags.map(function(a){return '<span class="tag">'+a+'</span>'}).join('');
		txt = txt.replace("{tags}", tags);
		// long_description
		txt = txt.replace("{long_description}", content.long_description.split(new RegExp("\\n\\n", 'g')).join("</p><p>").replace(new RegExp("\\n", 'g'), "<br/>"));
		$.each(projects[i][settings.language], function(index, value) {
			txt = txt.replace(new RegExp("{" + index + "}", 'g'), value);
		});

		// console.log(txt);
		return txt;
	}

	// Puts and @ in the email address
	var decipherMail = function () {
		// $(".email").attr("href", $(".email").attr("href").replace("---", "@"));
		$("#email").text($("#email").text().replace("---", "@"));
	}

	var switchLanguage = function () {
		// Animation + change view
		  $( "#two" ).slideUp( ANIMATION_DURATION, updateLanguage);

		// Change settings
		settings.language = settings.language == "fr" ? "en" : "fr";
		
		return false;
	}

	var updateLanguage = function () {
		fillContent();
		fillProjects();
		// $( "#two" ).slideDown( ANIMATION_DURATION );
	}<commit_msg>Internationalization<commit_after>(function() {
	
	'use strict';

	var PROJECTS_PREFIX = './projects/';
	var PROJECTS_JSON_SUFFIX = '.json';
	var PROJECTS_TXT_SUFFIX = '.txt';
	var PROJECT_TEMPLATE = "\
		<article class='6u 12u$(xsmall) work-item'>\
			<a href='{link}' data-poptrox='{poptroxData}' class='image fit thumb' id='{id}'><img src='images/thumbs/{id}.jpg' alt='' /></a>\
			<h3>{title}</h3>\
			<p>{short_description}</p>\
		</article>\
		";
	var CAPTION_TEMPLATE = "\
		<h3>{title}</h3>\
		<div class='tags'>{tags}</div>\
		<p>{long_description}</p>\
		";
	var ANIMATION_DURATION = 750;

	var settings = {
		"language": "fr",
		"possibleLanguages": ["fr", "en"]
	};

	var projects = {}

	var nbProjects = 0;

	var nbRequestToComeBack = 0;

	// URI util
	function get(name){
		if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
			return decodeURIComponent(name[1]);
	}

	// Detects browser language and save it
	var detectBrowserLanguage = function () {
		settings.language = (get("l") || navigator.language || navigator.userLanguage) != "fr" ? "en" : "fr";
		// console.log(settings.language);
	}

	// Takes content.js info and fill the blanks
	var fillContent = function () {
		
		$.each(info, function(index, value) {
			// console.log(index);
			$(index).html(value[settings.language]);
		});
	}

	// Donwloads all the projects
	var getProjects = function (callback) {
		fileExist(++nbProjects, function(){
			// console.log("Call callback");
			// callback();
		}.bind(callback),
		function(data){
			// Success callback
			loadProject(data, callback);
			// console.log("Found " + nbProjects + " projects");
			getProjects(callback);
		}.bind(callback))
	}

	var loadProject = function(data, callback) {
		var id = nbProjects;
		projects[id] = data;

		for (var i = settings.possibleLanguages.length - 1; i >= 0; i--) {
			var lang = settings.possibleLanguages[i];
			var targetUrl = PROJECTS_PREFIX + nbProjects + "." + lang + PROJECTS_TXT_SUFFIX;
			// console.log(targetUrl);
			nbRequestToComeBack++;
			$.ajax({
				url: targetUrl,
				dataType: "text",
				error: function(jqXHR, textStatus, errorThrown ){
					// If we don't find the page, log it and don't block
					console.warn("Coudn't find post " + id + " in " + lang);
					console.warn(textStatus);
					nbRequestToComeBack--;
				}.bind(id, lang),
				success: function(l, data, textStatus){
					nbRequestToComeBack--;
					// console.log("got " + id + " in " + l);
					// console.log(data);
					// console.log(l);
					projects[id][l].long_description = data;
					if (nbRequestToComeBack == 0) {
						callback();
					}
				}.bind(id, lang)
			});
		}
		// console.log(projects[nbProjects]);
	}

	// Test if a file exist and execute a callback according to the result
	var fileExist = function (idx, errorCallback, successCallback){
		var ret;

		$.ajax({
			url: PROJECTS_PREFIX + idx + PROJECTS_JSON_SUFFIX,
			dataType: "json",
			error: errorCallback,
			success: successCallback
		});
	}

	// Fills the project part
	var fillProjects = function () {
		$("#projects").html("");

		for (var i = nbProjects - 1 ; i > 0 ; i--) {
			var txt = PROJECT_TEMPLATE;
			console.log(projects[i].media.type == "image");
			// Set media type
			if (projects[i].media.type == "image") {
				txt = txt.replace("{link}", "images/fulls/{id}.jpg");
				txt = txt.replace("data-poptrox='{poptroxData}' ", "");
			} else {
				txt = txt.replace("{poptroxData}", projects[i].media.type);
				txt = txt.replace("{link}", projects[i].media.content);
			}
			
			// Set div to left of right
			if (i%2==0) {
				txt = txt.replace("6u", "6u$");
			}

			// Fill content of the project
			var content = projects[i][settings.language];
			// id
			txt = txt.replace(new RegExp("{id}", 'g'), i);
			// other
			$.each(projects[i][settings.language], function(index, value) {
				txt = txt.replace(new RegExp("{" + index + "}", 'g'), value);
			});
			console.log(txt);
			
			$("#projects").append(txt);
		}

		$('#two').poptrox({
			// caption: function($a) { return $a.next('div').html(); },
			caption: fillCaption,
			overlayColor: '#2c2c2c',
			overlayOpacity: 0.85,
			popupCloserText: '',
			popupLoaderText: '',
			selector: '.work-item a.image',
			usePopupCaption: true,
			usePopupDefaultStyling: false,
			usePopupEasyClose: false,
			usePopupNav: true,
			windowMargin: (skel.breakpoint('small').active ? 0 : 50)
			// onPopupOpen: fillProjectContent
		});
	}

	var fillCaption = function (a) {
		
		var i = a[0].id;

		var txt = CAPTION_TEMPLATE;
		var content = projects[i][settings.language];

		// Title
		txt = txt.replace("{title}", content.title);
		// Tags
		var tags = content.tags.map(function(a){return '<span class="tag">'+a+'</span>'}).join('');
		txt = txt.replace("{tags}", tags);
		// long_description
		txt = txt.replace("{long_description}", content.long_description.split(new RegExp("\\n\\n", 'g')).join("</p><p>").replace(new RegExp("\\n", 'g'), "<br/>"));
		$.each(projects[i][settings.language], function(index, value) {
			txt = txt.replace(new RegExp("{" + index + "}", 'g'), value);
		});

		// console.log(txt);
		return txt;
	}

	// Puts and @ in the email address
	var decipherMail = function () {
		// $(".email").attr("href", $(".email").attr("href").replace("---", "@"));
		$("#email").text($("#email").text().replace("---", "@"));
	}

	var switchLanguage = function () {
		// Animation + change view
		  $( "#two" ).slideUp( ANIMATION_DURATION, updateLanguage);

		// Change settings
		settings.language = settings.language == "fr" ? "en" : "fr";
		
		return false;
	}

	var updateLanguage = function () {
		fillContent();
		fillProjects();
		$( "#two" ).slideDown( ANIMATION_DURATION );
	}
{'fraction_non_alphanumeric': 0.19569644912777828, 'fraction_numerical': 0.0055786770565837245, 'mean_word_length': 3.382615444315095, 'pattern_counts': {'":': 4, '<': 43, '<?xml version=': 0, '>': 47, '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': '4476055', 'n_tokens_mistral': 4512, 'n_tokens_neox': 3905, 'n_words': 833}