Git Product home page Git Product logo

Comments (6)

Stichoza avatar Stichoza commented on July 22, 2024

Well, that's weird. Those words are translating with no problem, but an empty result error occurs on some languages.

screen shot 2014-10-21 at 05 02 52

from google-translate-php.

quanglam2807 avatar quanglam2807 commented on July 22, 2024

I think I have found the solution for this case.
So if Google Translate does not return the result, we add some special characters to the string and then send it to Google, then remove the special characters in the result.

Example:
'Physics' from 'en' to 'vi', return false;
'Physics $$$' from 'en' to 'vi' , return 'Vật lý $$$';
remove ' $$$' => 'Vật lý'

from google-translate-php.

Stichoza avatar Stichoza commented on July 22, 2024

Maybe it's somehow related to $urlFormat parameters? Honestly, I just copied this URL from http://translate.google.com/ and I have no idea what means the multires=1&otf=1&pc=1&trs=1&ssel=3&tsel=6&sc=1 part in URL

from google-translate-php.

aaajeetee avatar aaajeetee commented on July 22, 2024

I have the exact same problem. I however have debugged it to the json_decode in the static function staticTranslate:

$result = preg_replace('!,+!', ',', self::makeCurl($url)); // remove repeated commas (causing JSON syntax error)
$resultArray = json_decode($result, true);

With the use of 'json_last_error_msg ()' I got this error: "unexpected character". The json returned from the example above is this:

[[["en","en","","en"]],"ru",[["en",[1],true,false,1000,0,1,0]],[["en",1,[["en",1000,true,false]],[[0,2]],"en"]],[,"ен",[6]],2]

As you can see, there is a "[,", at the end just before 'ен'. This is the Google Translate's suggestion which is automatically returned. This is invalid json syntax however (according to PHP).

Adding this line before the json_decode() fixes the problem (not thoroughly tested though!):

$result = str_replace ("[,", "[", $result);

So this will be the new code:

$result = preg_replace('!,+!', ',', self::makeCurl($url)); // remove repeated commas (causing JSON syntax error)
$result = str_replace ("[,", "[", $result);
$resultArray = json_decode($result, true);

from google-translate-php.

edroque93 avatar edroque93 commented on July 22, 2024

I had the same problem, an empty value returned by Google. I fixed it in the same way as you did and it's working fine for me.

from google-translate-php.

Stichoza avatar Stichoza commented on July 22, 2024

@aaajeetee @edroque93 hey guys, can you make a pull request for this bug? :3

from google-translate-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.