下載谷歌組件php
composer require google/cloud-debugger
若是中途下載很慢,那麼請切換中文鏡像shell
若是中途報錯mismatch啥啥啥緩存
那是composer 緩存過小 composer
composer config -ldom
composer config --global cache-files-maxsize 1024MiB
支持語言:ui
https://cloud.google.com/translate/docs/languages?hl=zh-CNgoogle
接口:debug
https://cloud.google.com/translate/docs/?hl=zh-CNcode
案例:orm
https://cloud.google.com/translate/docs/translating-text?hl=zh-CN#translate_translate_text-php
Uncaught Google\Cloud\Core\Exception\ServiceException: { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { "message": "The request is missing a valid API key.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } }
45美金/小時 GG
點擊便可執行如下操做:
您能夠隨時在 GCP Console 中查看和管理這些資源。
將環境變量 GOOGLE_APPLICATION_CREDENTIALS 設置爲包含服務賬號密鑰的 JSON 文件的文件路徑。此變量僅適用於當前的 shell 會話,所以,若是您打開新的會話,請從新設置該變量。
composer require google/cloud-translate # Includes the autoloader for libraries installed with composer require __DIR__ . '/vendor/autoload.php'; # Imports the Google Cloud client library use Google\Cloud\Translate\TranslateClient; # Your Google Cloud Platform project ID $projectId = 'YOUR_PROJECT_ID'; # Instantiates a client $translate = new TranslateClient([ 'projectId' => $projectId ]); # The text to translate $text = 'Hello, world!'; # The target language $target = 'ru'; # Translates some text into Russian $translation = $translate->translate($text, [ 'target' => $target ]); echo 'Text: ' . $text . ' Translation: ' . $translation['text'];