Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. $.fn.extend({
  2.   translate: function(sourceLang, targetLang) {
  3.     if($(this).text().trim().length < 1 || !isNaN(parseInt($(this).text().trim())) || sourceLang == targetLang)
  4.       return;
  5.  
  6.     let $function = this;
  7.  
  8.     $($function).each(function() {
  9.       let $each = this;
  10.       $.ajax({
  11.         url: 'https://translate.yandex.net/api/v1.5/tr.json/translate',
  12.         method: 'GET',
  13.         dataType: 'JSONP',
  14.         crossDomain: true,
  15.         data: {
  16.           key: /* my-secret-key */,
  17.           text: $($each).text(),
  18.           lang: sourceLang + '-' + targetLang
  19.         },
  20.         success: function(response) {
  21.           try {
  22.             if(response.code !== 200)
  23.               throw "Response: " + response.code;
  24.             $($each).text(response.text[0])
  25.           } catch(error) {
  26.             console.error('Translation error on element: ', $($function).text());
  27.             console.error('Message returned by the server:', error);
  28.           }
  29.         },
  30.         error: function(xhr, status, error) {
  31.           console.error('Translation error on element: ', $($function).text());
  32.           console.error('Message returned by the server:', xhr.responseText);
  33.         }
  34.       });
  35.     });
  36.   }
  37. });
  38.    
  39. $(document).ready(function() {
  40.     let lang = $('html').attr('lang').split('-')[0];
  41.     $('td td:visible').translate(lang, "en");
  42. });
  43.    
  44. let iv = setInterval(function() {
  45.     let lang = $('html').attr('lang').split('-')[0];
  46.     let rows = $('tbody td:visible');
  47.     if(rows.length > 0) {
  48.         rows.translate(lang, "en");
  49.         clearInterval(iv);
  50.     }
  51. }, 1000);
  52.    
  53. let isTranslated = false;
  54. while(!isTranslated) {
  55.     let lang = $('html').attr('lang').split('-')[0];
  56.     let rows = $('tbody td:visible');
  57.     if(rows.length > 0) {
  58.         rows.delay(1000).translate(lang, "en");
  59.         isTranslated = true;
  60.     }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top