<commit_before>/**
 * The user's current locale
 */
Saiku.i18n = {
    locale: (navigator.language || navigator.browserLanguage || 
        navigator.systemLanguage || navigator.userLanguage).substring(0,2),
    po_file: {},
    translate: function() {
        $('.i18n').i18n(Saiku.i18n.po_file);
    },
    automatic_i18n: function() {
        // Load language file if it isn't English
        if (Saiku.i18n.locale != "en") {
            $.ajax({
                url: "js/saiku/plugins/I18n/po/" + Saiku.i18n.locale + ".json",
                type: 'GET',
                dataType: 'json',
                success: function(data) {
                    Saiku.i18n.po_file = data;
                    Saiku.i18n.translate();
                }
            });
        }
        
        return true;
    },
    elements: []
};

(function( $ ){
	/**
	 * Internationalize selected elements with the provided PO file
	 */
	$.fn.i18n = function(po_file) {
		// If no PO file is provided, then don't translate anything
		if (! po_file)
			return this;
		
		// If key is not found, return original language
		var translate = function(key, po_file) {
			if (typeof po_file[key] == "undefined") {
				return "";
			} else {
				return po_file[key];
			}
		};		

		// Iterate over UI elements that need to be translated
		return $.each(this, function() {
			element = $(this);
			
			// Translate text
			if (element.html()) {
				translated_text = translate( element.html(), po_file );
				if (translated_text) {
				    if (Saiku.i18n.elements.indexOf(element.html()) === -1) {
				        Saiku.i18n.elements.push(element.html());
				    }
					element.data('original', element.html());
					element.html(translated_text);
					element.removeClass('i18n');
				}
			}
			
			// Translate title
			if (element.attr('title')) {
				translated_title = translate( element.attr('title'), po_file );
				if (translated_title) {
				    if (Saiku.i18n.elements.indexOf(element.attr('title')) === -1) {
                        Saiku.i18n.elements.push(element.attr('title'));
                    }
					element.data('original', element.attr('title'));
					element.attr({ 'title': translated_title });
					element.removeClass('i18n');
				}
			}
			
			// Remove class so this element isn't repeatedly translated
			if (element.hasClass('i18n')) {
			    element.addClass('i18n_failed');
			}
			element.addClass('i18n_translated');
		});
	};
	
	$.fn.un_i18n = function() {
		// Iterate over UI elements to replace the original text
		return $.each(this, function() {
			element = $(this);
			
			if (element.text())
				element.text(element.data('original'));
			
			if (element.attr('title'))
				element.attr({ 'title': element.data('original') });
			
			element.addClass('i18n');
			element.removeClass('i18n_translated')
			    .removeClass('i18n_failed');
		});
	};
})( jQuery );

/**
 * Automatically internationalize the UI based on the user's locale
 */
Saiku.i18n.automatic_i18n();

/** 
 * Add translate button
 */
Saiku.events.bind('toolbar:render', function(args) {
    var $link = $("<a />").attr({ 
            href: "#translate",
            title: "Improve this translation"
        })
        .addClass('sprite translate');
    var $li = $("<li />").append($link);
    $(args.toolbar.el).find('ul').append($li);
});

/**
 * Bind to new workspace
 */
Saiku.events.bind('session:new', function() {    
    // Translate elements already rendered
    Saiku.i18n.translate();
    
    // Translate new workspaces
    Saiku.session.bind('tab:add', Saiku.i18n.translate);<commit_msg>Added placeholder for translation submission<commit_after>/**
 * The user's current locale
 */
Saiku.i18n = {
    locale: (navigator.language || navigator.browserLanguage || 
        navigator.systemLanguage || navigator.userLanguage).substring(0,2),
    po_file: {},
    translate: function() {
        $('.i18n').i18n(Saiku.i18n.po_file);
    },
    automatic_i18n: function() {
        // Load language file if it isn't English
        if (Saiku.i18n.locale != "en") {
            $.ajax({
                url: "js/saiku/plugins/I18n/po/" + Saiku.i18n.locale + ".json",
                type: 'GET',
                dataType: 'json',
                success: function(data) {
                    Saiku.i18n.po_file = data;
                    Saiku.i18n.translate();
                }
            });
        }
        
        return true;
    },
    elements: [],
    improve_translation: function() {
        alert("I'm glad you're willing, but this feature hasn't been implemented yet");
        return false;
    }
};

(function( $ ){
	/**
	 * Internationalize selected elements with the provided PO file
	 */
	$.fn.i18n = function(po_file) {
		// If no PO file is provided, then don't translate anything
		if (! po_file)
			return this;
		
		// If key is not found, return original language
		var translate = function(key, po_file) {
			if (typeof po_file[key] == "undefined") {
				return "";
			} else {
				return po_file[key];
			}
		};		

		// Iterate over UI elements that need to be translated
		return $.each(this, function() {
			element = $(this);
			
			// Translate text
			if (element.html()) {
				translated_text = translate( element.html(), po_file );
				if (translated_text) {
				    if (Saiku.i18n.elements.indexOf(element.html()) === -1) {
				        Saiku.i18n.elements.push(element.html());
				    }
					element.data('original', element.html());
					element.html(translated_text);
					element.removeClass('i18n');
				}
			}
			
			// Translate title
			if (element.attr('title')) {
				translated_title = translate( element.attr('title'), po_file );
				if (translated_title) {
				    if (Saiku.i18n.elements.indexOf(element.attr('title')) === -1) {
                        Saiku.i18n.elements.push(element.attr('title'));
                    }
					element.data('original', element.attr('title'));
					element.attr({ 'title': translated_title });
					element.removeClass('i18n');
				}
			}
			
			// Remove class so this element isn't repeatedly translated
			if (element.hasClass('i18n')) {
			    element.addClass('i18n_failed');
			}
			element.addClass('i18n_translated');
		});
	};
	
	$.fn.un_i18n = function() {
		// Iterate over UI elements to replace the original text
		return $.each(this, function() {
			element = $(this);
			
			if (element.text())
				element.text(element.data('original'));
			
			if (element.attr('title'))
				element.attr({ 'title': element.data('original') });
			
			element.addClass('i18n');
			element.removeClass('i18n_translated')
			    .removeClass('i18n_failed');
		});
	};
})( jQuery );

/**
 * Automatically internationalize the UI based on the user's locale
 */
Saiku.i18n.automatic_i18n();

/** 
 * Add translate button
 */
Saiku.events.bind('toolbar:render', function(args) {
    var $link = $("<a />").attr({ 
            href: "#translate",
            title: "Improve this translation"
        })
        .click(Saiku.i18n.improve_translation)
        .addClass('sprite translate i18n');
    var $li = $("<li />").append($link);
    $(args.toolbar.el).find('ul').append($li);
});

/**
 * Bind to new workspace
 */
Saiku.events.bind('session:new', function() {    
    // Translate elements already rendered
    Saiku.i18n.translate();
    
    // Translate new workspaces
    Saiku.session.bind('tab:add', Saiku.i18n.translate);
{'fraction_non_alphanumeric': 0.15842787682333873, 'fraction_numerical': 0.016747703943814155, 'mean_word_length': 2.401469912723932, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2207131', 'n_tokens_mistral': 2668, 'n_tokens_neox': 2248, 'n_words': 478}