PHP code example of naimkhalifa / laravel-google-cloud-translation

1. Go to this page and download the library: Download naimkhalifa/laravel-google-cloud-translation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

naimkhalifa / laravel-google-cloud-translation example snippets



return [

    /*
    |--------------------------------------------------------------------------
    | Google Cloud Translation API Key
    |--------------------------------------------------------------------------
    |
    | Your Google Cloud Translation API Key.
    | You can get it from https://console.cloud.google.com/apis/credentials
    | More info at https://cloud.google.com/translate/docs/setup
    |
    */
    'api_key' => env('GOOGLE_CLOUD_TRANSLATION_API_KEY'),

    /*
    |--------------------------------------------------------------------------
    | Default Source Language
    |--------------------------------------------------------------------------
    |
    | The default source language to translate from.
    | You can find the list of supported languages here:
    | https://cloud.google.com/translate/docs/languages
    |
    */
    'default_source_language' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Default Target Language
    |--------------------------------------------------------------------------
    |
    | The default target language to translate to.
    | Obviously, it must be different from the default source language.
    |
    */
    'default_target_language' => 'es',

    /*
    |--------------------------------------------------------------------------
    | Default Format
    |--------------------------------------------------------------------------
    |
    | The default format to translate to.
    | Acceptable values are html or text.
    |
    */
    'default_format' => 'text',
];

# This would translate using default_source_language 
# and default_target_language config values
GoogleCloudTranslation::translate('Hello World');

# with options
GoogleCloudTranslation::translate('Hello World', [
  'source' => 'en',
  'target' => 'fr',
  'format' => 'text', # or 'html'
]);


GoogleCloudTranslation::translateBatch([
  'Something else',
  'Another string to translate',
  'And a third one because we can'
])

# You can also pass options to this method
GoogleCloudTranslation::translateBatch('Hello World', [
  'source' => 'en',
  'target' => 'fr',
  'format' => 'text', # or 'html'
]);
bash
php artisan vendor:publish --provider="NaimKhalifa\GoogleCloudTranslation\GoogleCloudTranslationServiceProvider"

php artisan google-cloud-translation:translate-lang-file [options]

php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php

php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php --dryrun=false