balazs-endresz / jquery-translate

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

translateTextNodes stops at < > characters #56

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
jquery-translate version: jquery.translate-1.4.7-debug-all.js
jQuery version: 1.4.1
browser: firefox
OS: Microsoft window 7

URL of the page, with non-minified JavaScript:

http://pisarevo.net/translate/get_web_page_mubbashar.php?url_page=http://www.dun
starltd.com/featured.php?start=20

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

http://pisarevo.net/translate/get_web_page_mubbashar.php this is my script 
which uses gooogle translate api to translate the page to english .this script 
get url using query stirng e.g 
url_page=http://www.dunstarltd.com/featured.php?start=20
and convert the page to english. this script work fine for some url but this 
"http://www.dunstarltd.com/featured.php?start=20" is not translated. I dont 
know why. Please help me

Please provide any additional information below.

Original issue reported on code.google.com by mubbasha...@gmail.com on 22 Nov 2010 at 9:29

GoogleCodeExporter commented 9 years ago
It looks like the `<` and `>` characters at the bottom of the page are causing 
this issue. Though I'm not yet sure why.

Original comment by balazs.endresz on 23 Nov 2010 at 1:30

GoogleCodeExporter commented 9 years ago
Thanks sir for your support. Ok i understand but when i try to do the 
translation on google they translate the page. Can you suggest me some other 
way to translate the complete page. Please

Original comment by mubbasha...@gmail.com on 23 Nov 2010 at 1:38

GoogleCodeExporter commented 9 years ago
The same issue was reported here: 
http://code.google.com/p/jquery-translate/issues/detail?id=52
The problem is in the regexes in $.translate.trunctate function, which has to 
parse some HTML too if one's using $("body").translate(). And AFAIK that's just 
can't be done properly with regexes, though my code could be improved for sure.

But since you are using .translateTextNodes(), it doesn't have to deal with 
html, so the following patch should make it work properly:

$.translate.truncate = function(text, limit){
        var i, m1, m2, m3, m4, t, encoded = encodeURIComponent( text );

        for(i = 0; i < 10; i++){
            try { 
                t = decodeURIComponent( encoded.substr(0, limit - i) );
            } catch(e){ continue; }
            if(t) break;
        }

        return  ( !( m1 = null && /<(?![^<]*>)/.exec(t) ) ) ? (  //if no broken tag present
            ( !( m2 = null && />\s*$/.exec(t) ) ) ? (  //if doesn't end with '>'
                ( m3 = this._m3.exec(t) ) ? (  //if broken sentence present
                    ( m4 = null && />(?![^>]*<)/.exec(t) ) ? ( 
                        m3.index > m4.index ? t.substring(0, m3.index+1) : t.substring(0, m4.index+1)
                    ) : t.substring(0, m3.index+1) ) : t ) : t ) : t.substring(0, m1.index);

    }

Original comment by balazs.endresz on 23 Nov 2010 at 1:56

GoogleCodeExporter commented 9 years ago
thanks for your quick response.where i have to put this code.

Original comment by mubbasha...@gmail.com on 23 Nov 2010 at 2:00

GoogleCodeExporter commented 9 years ago
After you include the plugin.

Original comment by balazs.endresz on 23 Nov 2010 at 2:03

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
so you mean that after  
<script type="text/javascript" 
src="jquery.translate-1.4.7-debug-all.js"></script>

i have to make a java script tag and have to put all the above code there.And 
it will work fine.

Original comment by mubbasha...@gmail.com on 23 Nov 2010 at 3:30

GoogleCodeExporter commented 9 years ago
can you please provide a simple example of doing this. I tried this but this is 
not working for me

Original comment by mubbasha...@gmail.com on 23 Nov 2010 at 3:43

GoogleCodeExporter commented 9 years ago
I tried it on the original page, and it worked there... I'll have a look at it 
a bit later!

Original comment by balazs.endresz on 23 Nov 2010 at 4:17

GoogleCodeExporter commented 9 years ago
can you see my page ? Please have a look

Original comment by mubbasha...@gmail.com on 23 Nov 2010 at 4:19

GoogleCodeExporter commented 9 years ago
I looked at your page and it looks like it really can't be solved that easily. 
I'll try to do something with it tomorrow!

Original comment by balazs.endresz on 23 Nov 2010 at 7:35

GoogleCodeExporter commented 9 years ago
Sir can you please look my page.
Me waiting 

Original comment by mubbasha...@gmail.com on 24 Nov 2010 at 6:37

GoogleCodeExporter commented 9 years ago
Sir please help me i waiting for you for 2 days. Please help me

thanks in advance

Original comment by mubbasha...@gmail.com on 26 Nov 2010 at 1:43

GoogleCodeExporter commented 9 years ago
Issue 57 has been merged into this issue.

Original comment by balazs.endresz on 11 Mar 2011 at 7:44

GoogleCodeExporter commented 9 years ago
Issue 52 has been merged into this issue.

Original comment by balazs.endresz on 11 Mar 2011 at 7:45