balazs-endresz / jquery-translate

Automatically exported from code.google.com/p/jquery-translate
5 stars 5 forks source link

Some fix for correct work with BING #85

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello developers, 

First of all thank you for best Project and excellent code.

With Bing I have much errors so I added some modification to code, now all look 
like all work.

developer may check self file with help Diff, and may be some thing write more 
best. Sorry not all place in code was clear.

1. In bing after translate I have white spaces between </div> and next <div> 
For solution I added to _process: function()
below row:
   this.rawTranslation = this.rawTranslation.replace(/<\/div>\W<div>/gim,'</div><div>') ;

2. some text was bad formated so I replace in function "_translate" line:
data: {appId: key, from: _this.from, to: _this.to, contentType: "text/plain", 
text: src },
to 
data: {appId: key, from: _this.from, to: _this.to, contentType: "text/html", 
text: src },

3. because all continue not work 
I return old version code in function "_process" I replace so line (may be I 
not right)
if(j++ < n)

replace to
  if(j < n)

4. All at top give some result but all continue not work.
so I go to function "_init"

And replace below code:
            substr = this.truncate( this.rawSource.substr(lastpos), o.limit);
             if(!substr) break;
             this.rawSources.push(substr);
             lastpos += substr.length;

to code:

            size_for_translat = 0 ;
            substr = "";
            for(var kk = 0; kk < this.source.length; kk++){
              text_for_translate = '<div>'+this.source[kk]+'</div>';
              len = text_for_translate.length ; 
              if( (size_for_translat + len ) < o.limit )  {
                size_for_translat = size_for_translat + len;
                substr += text_for_translate ; 
              } else {

                this.rawSources.push(substr);
                size_for_translat = len;
                substr = text_for_translate ; 
              }
            }

            if(substr) this.rawSources.push(substr);
            break;

after that all start work good. So may be 1. 2. 3. points may return to 
original state.

In attachment my file result:
Every developer may check self file with help Diff, and may be some thing write 
more best. 

At end small promotion: at http://ordasoft.com - you may download work version 
for site translate build on joomla CMS and yours code. Project: sef Translate.

Thank you very much all !
Andrew

Original issue reported on code.google.com by akb...@gmail.com on 6 Dec 2011 at 8:14

Attachments:

GoogleCodeExporter commented 9 years ago
Dear / Sir Madam,

This works for a chuck of text on my page, but when doing the following it just 
pulls the last letter.

$.getScript('../jquery.translate.js', function(){ 
$.translate.load('301C79ACA55C1ECCD790B3131DE91DFA1205895A');
$.translate( 'some text', 'en', 'de', {
  complete: function(translation){ alert(translation); }
});

});

So 'some text' returns alert with just 't' in it.

Regards

Bykenhulle

Original comment by Ross.N.B...@gmail.com on 6 Dec 2011 at 10:24

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello,

thank you for all, but can you tell me how I can use your jquery.translate.js ?
On my web site it don't work !
I am using old code for Google Translate (without Bing).
This is the code :

<script type="text/javascript" src="catalog/view/javascript/jquery.js"></script>
<script type="text/javascript" 
src="catalog/view/javascript/jquery.translate.js"></script>
<script type="text/javascript" 
src="catalog/view/javascript/jquery.cookie.pack.js"></script>

<script type="text/javascript"> 
jQuery(function($){ //when DOM is ready  

  $.translate(function(){  //when the Google Language API is loaded  

    function translateTo( destLang ){

    var tlc = $.translate().toLanguageCode // create a shorthand

    if( tlc( destLang ) == "it" && tlc($.cookie("destLang")) == "it") // hide loading icon when surfing in English
        return;

          $.translate.load('my appid from Bing');

          $('body').translate( 'italian', destLang, {   //translate from english to the selected language  
          not: '.translate_dropdown',  //by default the generated element has this id   
          fromOriginal:true,   //always translate from english (even after the page has been translated)  
          start: function(){ $('#throbber').show() },   // show loading icon 
          complete: function(){ $('#throbber').hide() },  // hide loading icon 
          error: function(){ $('#throbber').hide() }  // hide loading icon 
           });  
    }  

       $.translate().ui('select','option')
     .val('Italian')
         .appendTo('#translate_dropdown')    //insert the element to the page
         .change(function(){   //when selecting another language

           translateTo( $(this).val() );

           $.cookie('destLang', $(this).val() );
           // set a cookie to remember the selected language

           return false; //prevent default browser action
         })

  $('#flags a') // added to include the flag thing
       .val('Italian')
       .click(function(){ 
         var lang = $(this).attr('id'); 
         translateTo( lang ); 
         $.cookie('destLang', lang );
         return false; 

      })  

    var destLang = $.cookie('destLang'); //get previously translated language  

    if( destLang )  //if it was set then  
        translateTo( destLang );

  }); //end of Google Language API loaded  

}) //end of DOM ready

</script>

With this code on Mozzilla Firefox I receive this error :
Key is undefined on line 729 of jquery.translate.js

Can you help me ?
Thank You

Original comment by virtuala...@gmail.com on 20 Dec 2011 at 2:18