PHP code example of wowworks / translation-google-sheet

1. Go to this page and download the library: Download wowworks/translation-google-sheet 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/ */

    

wowworks / translation-google-sheet example snippets


$client = new Google_Client();
$client->setApplicationName('Google Sheets API Wowworks');
$client->setScopes(Google_Service_Sheets::SPREADSHEETS);
$client->setAccessType('offline');
$client->setPrompt('select_account consent');

$pathToCredentialFile = 'pathToCredentialFile';
putenv("GOOGLE_APPLICATION_CREDENTIALS={$pathToCredentialFile}");
$client->useApplicationDefaultCredentials();
$serviceGoogleSheets = new Google_Service_Sheets($client);
$configurationService = new TranslationGoogleSheetConfigurationService(
    ['en_EN', 'ru_RU', 'de_DE'],
    ['ru_RU']
);

$service =  new TranslationGoogleSheetService(
            ['spreadSheetUrl1', 'spreadSheetUrl2'],
            $serviceGoogleSheets,
            $configurationService,
            new TranslationStringConverter()
);

$allPathsToTranslations = $configurationService->getAllPathsToTranslations(Yii::$app->i18n->translations);
$service->pull($allPathsToTranslations);
$service->push($allPathsToTranslations);