Solvedgoogle translate php Low quality translation compared to google live translator

I noticed that current repo isn't accurate translate anymore. Looks like it happened few weeks ago.

For example, im trying to translate from "en" to "ru" this phrase:
My apologies about my messages, hope they weren't too inconvenient. Hope everything will get back to normal soon.

Here is what I got from google in browser
Приношу свои извинения по поводу моих сообщений, надеюсь, они не были слишком неудобными. Надеюсь, что скоро все вернется на круги своя.

While library translate it like this:
Мои извинения о моих сообщениях, надеюсь, они не были слишком неудобны. Надеюсь, что все скоро вернется к нормам.

Which have a way more direct translation.

Any thoughts ?

36 Answers

✔️Accepted Answer

Hi, i'm coming with some new updates. So, in order to use the function that generates the "tk" token, we need to get a key that is only available on a file provided by Google itself:


That token should be used with a class that generate the token. I created a sample class.

class TokenGenerator {
    function getKey( $text, $token ) {
      	$tokenExploded 	=	explode( '.', $token );
      	$prefix 		=	( int ) $tokenExploded[0] ?? 0;
          	$data 	=	[],
          	$eIndex 	=	0,
          	$fIndex		=	0;
          	$fIndex < strlen( $text ); $fIndex++
        ) {
          	$stringPosition 	=	$this->charCodeAt( $text, $fIndex );
          	if ( 128 > $stringPosition ) {
              	$data[$eIndex++] 	=	$stringPosition;
            } else {
              	if ( 2048 > $stringPosition ) {
                  	$data[$eIndex++] = $stringPosition >> 6 | 192;
                } else if ( 
                  55296 == ( $stringPosition & 64512 ) && 
                  $fIndex + 1 < count( $text ) && 
                  56320 == $this->charCodeAt( $text, $fIndex + 1 ) & 64512 
                ) {
                  	$stringPosition 	=	65536 + ( ( $stringPosition & 1023 ) << 10 ) + $this->chartCodeAt( ++$fIndex ) & 1023;
                  	$data[$eIndex++] 	=	$stringPosition >> 18 | 240;
                  	$data[$eIndex++] 	=	$stringPosition >> 12 & 63 | 128;
                } else {
            		$data[$eIndex++] 	=	$stringPosition >> 12 | 224;
                  	$data[$eIndex++] 	=	$stringPosition >> 6 & 63 | 128;
                  	$data[$eIndex++] 	=	$stringPosition & 63 | 128;
      	$text 	=	$token;
      	for( $e = 0; $e < count( $data ) ; $e++ ) {
          	$text 	+=	$data[$e];
          	$text	=	$this->jrChars( $text, '+-a^+6' );
        $text 	=	$this->jrChars( $text, '+-3^+b+-f' );
        $text 	^=	( int ) $tokenExploded[1] ?? 0;

        if ( 0 > $text ) {
            $text 	=	( ( $text & 2147483647 ) + 2147483648 );

        return ( ( string ) $text %1E6 ) . ( '.' ) . ( $tokenExploded ^ $token );         
  	function charCodeAt($string, $offset) {
        $string = mb_substr($string, $offset, 1);
        list(, $ret) = unpack('S', mb_convert_encoding($string, 'UTF-16LE'));
        return $ret;
  	function jrChars($a, $b) {
      	for ($c = 0; $c < strlen( $b ) - 2; $c += 3) {
            $d = substr( $b, $c + 2);
            $d = "a" <= $d ? $this->charCodeAt( $d, 0 ) - 87 : ( int ) $d;
            $d = "+" == substr( $b, $c + 1) ? $a >> $d : $a << $d;
            $a = "+" == substr( $b, $c ) ? $a + $d & 4294967295 : ( $a ^ $d );
        return $a;

$generator 	=	new TokenGenerator;
$generator->getKey( 'Hello World', "451185.3571800534" ); // output : 493811.451184

I'll now do tests with Google to see whether it's effective or not.

Related Issues:

google translate php Low quality translation compared to google live translator
Hi i'm coming with some new updates So in order to use the function that generates the tk token ...
react native localize Dynamically change language inside app
@sWgiraffe @MrEdinLaw i had managed to dynamic language switch by using inside my main app App.js an...
laradock Mysql. The server requested authentication method unknown to the client [caching_sha2_password]
alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it....
framework query that worked in Laravel 5.2 gives me error in Laravel 5.3
Ok Laravel can also enable this mode when querying This query works in 5.2: my gallery table looks l...
framework [5.4] SQL error when migrating tables
In your appserviceprovider boot method try adding Best sure to import Illuminate\Support\Facades\Sch...
laradock SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
+1 I'm having the same problem here. Info: Docker version ($ docker --version): Docker version 17.12...
valet In Brew.php line 187: Unable to determine linked PHP.
I've had the same problem tonight I try methods: composer global update install php 72 brew upgrade ...
jwt auth Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify() must be an instance of Lcobucci\JWT\Signer\Key, null given
Run php artisan jwt:secret that works for me Subject of the issue Describe your issue here ...
psysh Not working after upgrading to PHP 7.3
May I know how do you open this file and drop in the code you mentioned? Thanks ...
laravel activitylog >PHP7.2: Declaration of Orchestra\Testbench\TestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp()
@AndresMatta in TestCase.php file add :void public function setUp(): void phpunit --coverage-text --...
jwt auth Method factory does not exist.
I fixed it changing this protected function: respondWithToken replace 'expires_in' => auth()->factor...
laradock MySQL Container fails to start
I had the same issue last night I think it's the mysql version problem What I did was edited laradoc...
jwt auth Install failed.
@Ekenzy-101 You can add --ignore-platform-reqs to force install it works well for me composer requir...
framework Laravel not compatiable with php 7.2
I solved the problem putting the next code at the beginning of the controller: If you don't know wha...
ddev In WSL2 ddev start fails at docker-credential-desktop.exe, "error listing credentials"
I had to set credsStore: in my ~/.docker/config.json .. it was previously set to credentials.exe ...
valet cURL error 6: Could not resolve: site.test (Domain name not found)
It's interesting that it's only curl that's giving trouble and only with Guzzle I'm not convinced th...
framework Laravel 5.8 update breaks third-party composer libraries
I've been going over the comments here a few times since the issue was opened again and want to say ...
framework sql_require_primary_key Causes Tables With String Primary Key To Fail
I've had the following response from DigitalOcean regarding this issue: I understand you are getting...
laravel backup Target [Spatie\Backup\Tasks\Cleanup\CleanupStrategy] is not instantiable while building
I found that ensuring the package is removed: composer remove spatie/laravel-backup clear the cache ...
framework php artisan make:auth conflicts with route:cache 'Unable to prepare route [api/user] for serialization. Uses Closure.'
@themsaid Please stop throwing responsibility on the others This is definitely a bug ...
framework Laravel 6 proc_open
It is because of Flare error reporting service enabled in debug mode There is a workaround for this ...
Laravel Excel Error Opening file with Excel. Possible data corrupted or bad file extension.
Hi everyone I spend my day to understand this unworkable download function PHPSpreadSheet seems to u...
framework Pass additional parameter to API Resource
@yanhao-li This is very much possible - you just have to overload the constructor of the Resource yo...
php amqplib Missing bcmath while installing package using official docker php:5.6 image
I found a solution bcmath can be installed by running this command inside a container: docker-php-ex...
valet Valet 2 uses wrong PHP version
I'm facing the same issue and I couldn't change it I upgraded my php71 to php72 using brew restarted...
laradock ERROR: 404 page not found
I had this problem because the root path in docker-compose.yml differs from the one in nginx default...
valet 502 Bad Gateway nginx/1.15.8
Started having this issue after I updated php to v7.3 Tried all of the suggestions ...
jwt auth Guide for setting up with Lumen?
Since there is demand for it Where's the current guide to setting up a recent version of jwt-auth (I...
laradock When Using docker-compose up mysql MySQL Doesn't Start
I solved this problem This is because of data folder I was running it using mysql 5.7 then abort it ...
laradock Guzzle/Curl connections between multiple projects
That's literary the only change you need to do not going to post the whole of docker-compose file in...
server Upgrade fails with - Column name "oc_flow_operations.entity" is "NotNull", but has empty string or null as default
I just got this error while upgrading from 17.0.10 to 18.0.10 Also with me the column entity did not...
framework Error creating a new project using PHP Version < 7.0
@ArronStudio @rkgarcia try to delete composer.lock file in root folder and run composer install agai...
framework [5.7] Sqlite & dropForeign
I found a way to replace sqlite connection don't update any migration Hopefully can help. ...
valet Upgraded PHP 7.4 - Error (The process has been signaled with signal 6 / 9.
For me the fix was the specific upgrade from nginx 1.15.9 to 1.17.8 by brew upgrade nginx Works like...
valet 504 Gateway Timeout
@bkkrishna I have solved my issue adding to ~/usr/local/etc/nginx.confg file under http {} object Th...
framework [5.4] "npm run watch" doesn't watch for changes on Windows.
npm run watch-poll works fine for me in laravel 5.4 Laravel Version: 5.4 PHP Version: 7.0 node v6.9....
laravel boilerplate Class 'Doctrine\DBAL\Driver\PDOSqlite\Driver' not found in TestCase
I guess it may be due to removing columns You need this package to solve this issue composer require...
LogViewer Log [] is not defined. Unable to create configured logger. Using emergency logger.
If you're using Laravel 5.6 you need to update your config files if you've migrated from an older la...
magento2 2.3.4 Email Template New Pickup Order or add New Template order items are missing in Mail
In case it helps anyone If you're using a custom template for your order emails ...
framework Laravel 6.3 Action Facade\Ignition\Http\Controllers\ShareReportController not defined
First see if the migrations have ran with php artisan migrate Try this if that doesn't work php arti...
Laravel Excel [BUG] import date format issue
I started working on a PR but quickly realized that it was going to be complicated to implement ...
magento2 Issue installing magento 2.3.5p1 on local server stuck at 51%
I found a workaround for Windows OS Image Adapter try opens to image files ('open function in
EasyAdminBundle Multiple file/images upload - OneupUploaderBundle
I got this to work with VichUploaderBundle Is there any possibility to manage upload multiple files?...
laravel permission There is no permission named edit articles for guard web.
I have read the source code i found that in HasPermission.php in line 117 I think it's a bug because...
symfony PHPUnit Test header already send by "phpunit-5.7/src/Util/Printer.php"
Symfony version 4.0.2 PHPUnit 6.5 I had got the same error solved by enabling :