<commit_before>/**
 * translate a string
 * @param app the id of the app for which to translate the string
 * @param text the string to translate
 * @return string
 */

function t(app,text){
	if( !( t.cache[app] )){
		$.ajax(OC.filePath('core','ajax','translations.php'),{
			async:false,//todo a proper sollution for this without sync ajax calls
			data:{'app': app},
			type:'POST',
			success:function(jsondata){
				t.cache[app] = jsondata.data;
			}
		});

		// Bad answer ...
		if( !( t.cache[app] )){
			t.cache[app] = [];
		}
	}
	if( typeof( t.cache[app][text] ) !== 'undefined' ){
		return t.cache[app][text];
	}
	else{
		return text;
	}
}
t.cache={};

/**
* Get the path to download a file
* @param file The filename
* @param dir The directory the file is in - e.g. $('#dir').val()
* @return string
*/
function fileDownloadPath(dir, file) {
	return OC.filePath('files', 'ajax', 'download.php')+'&files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir);
}<commit_msg>Suggestion for simple, yet efficient variable interpolation in js translations.<commit_after>/**
 * translate a string
 * @param app the id of the app for which to translate the string
 * @param text the string to translate
 * @return string
 */

function t(app,text, vars){
	if( !( t.cache[app] )){
		$.ajax(OC.filePath('core','ajax','translations.php'),{
			async:false,//todo a proper sollution for this without sync ajax calls
			data:{'app': app},
			type:'POST',
			success:function(jsondata){
				t.cache[app] = jsondata.data;
			}
		});

		// Bad answer ...
		if( !( t.cache[app] )){
			t.cache[app] = [];
		}
	}
	var _build = function(text, vars) {
		return text.replace(/{([^{}]*)}/g,
			function (a, b) {
				var r = vars[b];
				return typeof r === 'string' || typeof r === 'number' ? r : a;
			}
		);
	}
	if( typeof( t.cache[app][text] ) !== 'undefined' ){
		if(typeof vars === 'object') {
			return _build(t.cache[app][text], vars);
		} else {
			return t.cache[app][text];
		}
	}
	else{
		if(typeof vars === 'object') {
			return _build(text, vars);
		} else {
			return text;
		}
	}
}
t.cache={};

/**
* Get the path to download a file
* @param file The filename
* @param dir The directory the file is in - e.g. $('#dir').val()
* @return string
*/
function fileDownloadPath(dir, file) {
	return OC.filePath('files', 'ajax', 'download.php')+'&files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir);
}
{'fraction_non_alphanumeric': 0.1896265560165975, 'fraction_numerical': 0.0, 'mean_word_length': 3.6634429400386845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2040445', 'n_tokens_mistral': 911, 'n_tokens_neox': 851, 'n_words': 227}