Ignore:
Timestamp:
03/04/2010 02:12:58 AM (2 years ago)
Author:
ofer
Message:

Mass translation support for #80

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/js/transposhadmin.js

    r362 r386  
    1 /*  
    2  * To change this template, choose Tools | Templates 
    3  * and open the template in the editor. 
     1/*  Copyright © 2009-2010 Transposh Team (website : http://transposh.org) 
     2 * 
     3 *      This program is free software; you can redistribute it and/or modify 
     4 *      it under the terms of the GNU General Public License as published by 
     5 *      the Free Software Foundation; either version 2 of the License, or 
     6 *      (at your option) any later version. 
     7 * 
     8 *      This program is distributed in the hope that it will be useful, 
     9 *      but WITHOUT ANY WARRANTY; without even the implied warranty of 
     10 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     11 *      GNU General Public License for more details. 
     12 * 
     13 *      You should have received a copy of the GNU General Public License 
     14 *      along with this program; if not, write to the Free Software 
     15 *      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    416 */ 
    517 
     
    3648        jQuery.ajax({ 
    3749            type: "POST", 
    38             url: transposh_params.post_url, 
     50            url: t_jp.post_url, 
    3951            data: data, 
    4052            success: function() { 
     
    5062    }, 200); // wait 200 ms... 
    5163} 
    52 /* 
    5364 
    54             */ 
    55 //to run at start 
    56 jQuery.noConflict(); 
    57 google.load("language", "1"); 
    58  
    59 //read parameters 
    60 var transposh_params = new Array(); 
    61 var ext_langs = 'he|zh-tw|pt|fa|af|be|is|ga|mk|ms|sw|ws|cy|yi'; 
    62 jQuery("script[src*='transposhadmin.js']").each(function (j) { 
    63     var query_string = unescape(this.src.substring(this.src.indexOf('?')+1)); 
    64     var parms = query_string.split('&'); 
    65     for (var i=0; i<parms.length; i++) { 
    66         var pos = parms[i].indexOf('='); 
    67         if (pos > 0) { 
    68             var key = parms[i].substring(0,pos); 
    69             var val = parms[i].substring(pos+1); 
    70             transposh_params[key] = val; 
    71         } 
    72     } 
    73 }); 
    74  
    75 jQuery(document).ready(function() { 
    76     //var count = 0; 
     65function translate_post(postid) { 
     66    // count = 0; 
    7767    var p_count = 0; 
    7868    var prev_name=''; 
    7969    var l_count = 0; 
    80  
    81     jQuery.getJSON(transposh_params.post_url+"?tr_phrases_post=y&post="+transposh_params.post+"&random="+Math.random(), function(json) { // need to add random to avoid getting cached! 
     70    jQuery("#tr_loading").data("done",false); 
     71    jQuery.getJSON(t_jp.post_url+"?tr_phrases_post=y&post="+postid+"&random="+Math.random(), function(json) { // need to add random to avoid getting cached! 
    8272        // if we got no results than seems like we have nothing to translate 
    83         if (json == null) { 
    84              jQuery("#tr_loading").replaceWith('Nothing left to translate'); 
     73        jQuery("#tr_translate_title").html("Translating post: "+json.posttitle); 
     74        if (json.length === undefined) { 
     75            jQuery("#tr_loading").html('Nothing left to translate'); 
     76            jQuery("#tr_loading").data("done",true); 
    8577            return; 
    8678        } 
    8779        // create progress bars 
    88         jQuery("#tr_loading").replaceWith('Translating<br/>Phrase: <span id="p"></span><div id="progress_bar"/>Target lanaguage: <span id="l"></span><div id="progress_bar2"/><span id="r"></span>') 
     80        jQuery("#tr_loading").html('Translating<br/>Phrase: <span id="p"></span><div id="progress_bar"/>Target lanaguage: <span id="l"></span><div id="progress_bar2"/><span id="r"></span>'); 
    8981        jQuery("#progress_bar").progressbar({ 
    9082            value:0 
     
    9789            jQuery.each(val.l, function(id,lang) { 
    9890                // if (count <1000) { 
    99                     google.language.translate(name, "", lang, function(result) { 
    100                         if (!result.error) { 
    101                             // No longer need because now included in the ajax translate 
    102                             if (prev_name != name) { 
    103                                 prev_name = name; 
    104                                 l_count = 0; 
    105                                 p_count++; 
    106                             } 
    107                             jQuery("#progress_bar").progressbar('value' , p_count/json.length*100); 
    108                             l_count++; 
    109                             jQuery("#progress_bar2").progressbar('value' , l_count/val.l.length*100); 
    110                             jQuery('#p').text(jQuery("<div>"+name+"</div>").text()); 
    111                             jQuery('#l').text(lang); 
    112                             jQuery('#r').text(jQuery("<div>"+result.translation+"</div>").text()); 
    113                             ajax_translate_me(val.t,jQuery("<div>"+result.translation+"</div>").text(),lang); 
     91                google.language.translate(name, "", lang, function(result) { 
     92                    if (!result.error) { 
     93                        // No longer need because now included in the ajax translate 
     94                        if (prev_name != name) { 
     95                            prev_name = name; 
     96                            l_count = 0; 
     97                            p_count++; 
    11498                        } 
    115                     }); 
    116                     //count++; 
    117                 //} 
     99                        jQuery("#progress_bar").progressbar('value' , p_count/json.length*100); 
     100                        l_count++; 
     101                        jQuery("#progress_bar2").progressbar('value' , l_count/val.l.length*100); 
     102                        jQuery('#p').text(jQuery("<div>"+name+"</div>").text()); 
     103                        jQuery('#l').text(lang); 
     104                        jQuery('#r').text(jQuery("<div>"+result.translation+"</div>").text()); 
     105                        if (p_count === json.length && l_count === val.l.length) 
     106                            jQuery("#tr_loading").data("done",true); 
     107                        ajax_translate_me(val.t,jQuery("<div>"+result.translation+"</div>").text(),lang); 
     108                    } 
     109                }); 
     110            //count++; 
     111            //} 
    118112            }); 
    119113        }); 
    120114    }); 
     115} 
     116 
     117google.load("language", "1"); 
     118 
     119jQuery(document).ready(function() { 
     120    if (t_jp.post) { 
     121        translate_post(t_jp.post); 
     122    } 
    121123}); 
Note: See TracChangeset for help on using the changeset viewer.