Comments (6)
Well, that's weird. Those words are translating with no problem, but an empty result error occurs on some languages.
from google-translate-php.
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.
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.
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.
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.
@aaajeetee @edroque93 hey guys, can you make a pull request for this bug? :3
from google-translate-php.
Related Issues (20)
- setUrl() It is not available in mainland China HOT 1
- Memory Usage HOT 4
- Very slow HOT 1
- Country an cities sometimes are not translated HOT 4
- ErrorException: Maximum execution time of 60 seconds exceeded HOT 4
- Class "Stichoza\GoogleTranslate\GoogleTranslate" not found HOT 1
- How do I swap to using my own paid api key? HOT 1
- Loading Problem. HOT 2
- I use the IP of a VPN server as a proxy, I wonder why it doesn't work when I use 'https' instead? HOT 5
- Can you give me a list of free Proxies that I can use so that translation is not blocked in the future? HOT 1
- Can you fix this bug in your library for me?
- 400 Bad Request Client error: GET HOT 5
- Can you add the link of my package to your package? HOT 1
- Ignore escaped keys on translations HOT 4
- Error: Class "Stichoza\GoogleTranslate\GoogleTranslate" not found in file HOT 6
- Bug report: preserveParameters gives unexpected results when translating to French HOT 1
- cURL error 60: SSL certificate problem HOT 1
- Please assist me HOT 3
- How can I translate my page web HTML into your library? HOT 2
- PHP - extract the children from this <div id="page-container"> then translate it and put them back into this same <div id="page-container">
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-translate-php.