
(function(ext) {
    console.log('in function');
    var ext = this;
    // Cleanup function when the extension is unloaded
    ext._shutdown = function() {};

    // Status reporting code
    // Use this to report missing hardware, plugin or unsupported browser
    ext._getStatus = function() {
        return {status: 2, msg: 'Ready'};
    };
  
    ext.get_lang = function(text, callback){
	console.log('setting key');
	var apiKey="trnsl.1.1.20150605T132039Z.c660d54664d42d1d.3e02378e3b4f321ba39e2dee119909f8b402292a";
	console.log('starting ajax');
	var urltext = "https://translate.yandex.net/api/v1.5/tr.json/detect?key="+apiKey+"&text="+text+"&callback=myCallback";
	console.log(urltext);
	$.ajax({
		url: urltext,		
		dataType:'jsonp',
		success: function(language_results){
			langCode = language_results["lang"];
			callback(langCode);
		}
	});
    };
    // Block and block menu descriptions
    var descriptor = {
        blocks: [
		// Block type, block name, function name, param1 default value, param2 default value
            ['R', 'language of %s', 'get_lang','Hello world'],
        ]
    };

    // Register the extension
    ScratchExtensions.register('Detect Language', descriptor, ext);
})({});

@@ -62,16 +62,121 @@
  = this;
+i%0A    var apiKey=%22trnsl.1.1.20150605T132039Z.c660d54664d42d1d.3e02378e3b4f321ba39e2dee119909f8b402292a%22;%0A
 %0A    // 
@@ -445,18 +445,326 @@
 %0A    %7D;%0A
-  
+%09%0A    var langNames;%0A%0A    function getLanguagesFromCodes(language, code)%7B%0A%09$.ajax(%7B%0A%09%09url: %22https://translate.yandex.net/api/v1.5/tr.json/getLangs?key=%22+apiKey+%22&ui=%22+language+%22&callback=myCallback%22,%0A%09%09datatype:'jsonp',%0A%09%09success: function(langNames_res)%7B%0A%09%09%09langNames = langNames_res%5B%22langs%22%5D;%0A%09%09%7D%0A%09%7D);%0A%0A    %7D
 %0A    ext
@@ -826,24 +826,26 @@
 ting key');%0A
+//
 %09var apiKey=
@@ -1233,16 +1233,51 @@
 lang%22%5D;%0A
+%09%09%09langName = langNames%5BlangCode%5D;%0A
 %09%09%09callb
@@ -1284,19 +1284,19 @@
 ack(lang
-Cod
+Nam
 e);%0A%09%09%7D%0A

converting lang codes to name