Translate google with php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP class to use the Google Translator API for free.

License

statickidz/php-google-translate-free

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Читайте также:  Html сделать кнопку нажатая

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Simple PHP library for talking to Google’s Translate API for free.

Eliminates IP request limitations

composer require statickidz/php-google-translate-free 

Or edit your project’s composer.json to require statickidz/php-google-translate-free and then run composer update .

"require": < "statickidz/php-google-translate-free": "^1.2.1" >
require_once ('vendor/autoload.php'); use \Statickidz\GoogleTranslate; $source = 'es'; $target = 'en'; $text = 'buenos días'; $trans = new GoogleTranslate(); $result = $trans->translate($source, $target, $text); // Good morning echo $result;

About

PHP class to use the Google Translator API for free.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Library for free use Google Translator. With attempts connecting on failure and array support.

License

dejurin/php-google-translate-for-free

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Library for free use Google Translator. With attempts connecting on failure and array support.

composer require dejurin/php-google-translate-for-free 

Or edit your project’s composer.json to require dejurin/php-google-translate-for-free and then run composer update .

"require": < "dejurin/php-google-translate-for-free": "^1.0" >
require_once ('vendor/autoload.php'); use \Dejurin\GoogleTranslateForFree;
$source = 'en'; $target = 'ru'; $attempts = 5; $text = 'Hello'; $tr = new GoogleTranslateForFree(); $result = $tr->translate($source, $target, $text, $attempts); var_dump($result); /* string(24) "Здравствуйте" */
$source = 'en'; $target = 'ru'; $attempts = 5; $arr = ['hello','world']; $tr = new GoogleTranslateForFree(); $result = $tr->translate($source, $target, $arr, $attempts); var_dump($result); /* array(2)  [0]=> string(24) "Здравствуйте" [1]=> string(6) "Мир" > */

This source code is distributed under MIT license.

Источник

translate a PHP $string using google translator API

been google’ing for a while how is the best way to translate with google translator in PHP, found very different ways converting URLS, or using Js but i want to do it only with php (or with a very simple solution JS/JQUery) example:

//hopefully with $from_lan and $to_lan being like 'en','de', .. or similar function translate($from_lan, $to_lan, $text) < // do return $translated_text; >

can you give me a clue? or maybe you already have this function.. my intention it’s to use it only for the languages i have not already defined (or keys i haven’t defined), that’s why i wan it so simple, will be only temporal.. EDIT thanks for your replies we are now trying this soulutions:

function auto_translate($from_lan, $to_lan, $text)< // do $json = json_decode(file_get_contents('https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($text) . '&langpair=' . $from_lan . '|' . $to_lan)); $translated_text = $json->responseData->translatedText; return $translated_text; 

> (there was a extra ‘g’ on variables for lang. anyway) it returns: works now 🙂 i don’t really understand much the function, so any idea why is not acepting the object? (now i do) OR:

 function auto_translate($from_lan, $to_lan, $text)< // do // $json = json_decode(file_get_contents('https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($text) . '&langpair=' . $from_lan . '|' . $to_lan)); // $translated_text = $json['responseData']['translatedText']; error_reporting(1); require_once('GTranslate.php'); try< $gt = new Gtranslate(); $translated_text = $gt->english_to_german($text); > catch (GTranslateException $ge) < $translated_text= $ge->getMessage(); > return $translated_text; > 

And this one looks great but it doesn’t even gives me an error, the page won’t load (error_report(1) :S) thanks in advance!

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

googleapis/google-cloud-php-translate

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Google Cloud Translation for PHP

NOTE: This repository is part of Google Cloud PHP. Any support requests, bug reports, or development contributions should be directed to that project.

Dynamically translates text between thousands of language pairs. The Cloud Translation API lets websites and programs integrate with the translation service programmatically. The Google Translation API is part of the larger Cloud Machine Learning API family.

To begin, install the preferred dependency manager for PHP, Composer.

Now to install just this component:

$ composer require google/cloud-translate

Or to install the entire suite of components at once:

$ composer require google/cloud

Please see our Authentication guide for more information on authenticating your client. Once authenticated, you’ll be ready to start making requests.

Sample Using the Handwritten Client (Interacts with the V2 API)

require 'vendor/autoload.php'; use Google\Cloud\Translate\V2\TranslateClient; $translate = new TranslateClient([ 'key' => 'your_key' ]); // Translate text from english to french. $result = $translate->translate('Hello world!', [ 'target' => 'fr' ]); echo $result['text'] . "\n"; // Detect the language of a string. $result = $translate->detectLanguage('Greetings from Michigan!'); echo $result['languageCode'] . "\n"; // Get the languages supported for translation specifically for your target language. $languages = $translate->localizedLanguages([ 'target' => 'en' ]); foreach ($languages as $language) < echo $language['name'] . "\n"; echo $language['code'] . "\n"; > // Get all languages supported for translation. $languages = $translate->languages(); foreach ($languages as $language) < echo $language . "\n"; >

Sample Using the Generated Client (Interacts with the V3 API)

require 'vendor/autoload.php'; use Google\Cloud\Translate\V3\TranslationServiceClient; $translationClient = new TranslationServiceClient(); $content = ['one', 'two', 'three']; $targetLanguage = 'es'; $response = $translationClient->translateText( $content, $targetLanguage, TranslationServiceClient::locationName('[PROJECT_ID]', 'global') ); foreach ($response->getTranslations() as $key => $translation) < $separator = $key === 2 ? '!' : ', '; echo $translation->getTranslatedText() . $separator; >

Choosing the Right Client for You

This component offers both a handwritten and generated client, used to access the V2 and V3 translation APIs, respectively. Both clients will receive on-going support and feature additions, however, it is worth noting the streamlined nature of the generated client means it will receive updates more frequently. Additionally, the generated client is capable of utilizing gRPC for its transport (by installing the gRPC extension) while the handwritten client interacts over REST & HTTP/1.1 only.

The handwritten client can be found under Google\Cloud\Translate\TranslateClient , whereas the generated client is found under Google\Cloud\Translate\V3\TranslationServiceClient .

This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in any minor or patch releases. We will address issues and requests with the highest priority.

Источник

Оцените статью