Service Description: Provides natural language translation operations.

This class provides the ability to make remote calls to the backing service through method
calls that map to API methods. Sample code to get started:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedName = $translationServiceClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]');
    $operationResponse = $translationServiceClient->deleteGlossary($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }


    // Alternatively:

    // start the operation, keep the operation name, and resume later
    $operationResponse = $translationServiceClient->deleteGlossary($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'deleteGlossary');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
      $result = $newOperationResponse->getResult();
      // doSomethingWith($result)
    } else {
      $error = $newOperationResponse->getError();
      // handleError($error)
    }
} finally {
    $translationServiceClient->close();
}

Many parameters require resource names to be formatted in a particular way. To assist
with these names, this class includes a format method for each type of name, and additionally
a parseName method to extract the individual identifiers contained within formatted names
that are returned by the API.

  • experimental
CloneableInstantiable
Constants
public Google\Cloud\Translate\V3\Gapic\TranslationServiceGapicClient::CODEGEN_NAME = 'gapic'
 

The name of the code generator, to be included in the agent header.

public Google\Cloud\Translate\V3\Gapic\TranslationServiceGapicClient::DEFAULT_SERVICE_PORT = 443
 

The default port of the service.

public Google\Cloud\Translate\V3\Gapic\TranslationServiceGapicClient::SERVICE_ADDRESS = 'translate.googleapis.com'
 

The default address of the service.

public Google\Cloud\Translate\V3\Gapic\TranslationServiceGapicClient::SERVICE_NAME = 'google.cloud.translation.v3.TranslationService'
 

The name of the service.

Properties
public static $serviceScopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-translation']
 

The default scopes required by the service.

Methods
public __construct(array $options = [])
 

Constructor.

  • throws ValidationException
  • experimental
public batchTranslateText( $parent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig, array $optionalArgs = [])
 

Translates a large volume of text in asynchronous batch mode.

This function provides real-time output as the inputs are being processed.
If caller cancels a request, the partial results (for an input file, it's
all or nothing) may still be available on the specified output location.

This call returns immediately and you can
use google.longrunning.Operation.name to poll the status of the call.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]');
    $sourceLanguageCode = '';
    $targetLanguageCodes = [];
    $inputConfigs = [];
    $outputConfig = new OutputConfig();
    $operationResponse = $translationServiceClient->batchTranslateText($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }


    // Alternatively:

    // start the operation, keep the operation name, and resume later
    $operationResponse = $translationServiceClient->batchTranslateText($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'batchTranslateText');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
      $result = $newOperationResponse->getResult();
      // doSomethingWith($result)
    } else {
      $error = $newOperationResponse->getError();
      // handleError($error)
    }
} finally {
    $translationServiceClient->close();
}
public close()
 

Initiates an orderly shutdown in which preexisting calls continue but new
calls are immediately cancelled.

  • experimental
public createGlossary( $parent, $glossary, array $optionalArgs = [])
 

Creates a glossary and returns the long-running operation. Returns
NOT_FOUND, if the project doesn't exist.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]');
    $glossary = new Glossary();
    $operationResponse = $translationServiceClient->createGlossary($formattedParent, $glossary);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }


    // Alternatively:

    // start the operation, keep the operation name, and resume later
    $operationResponse = $translationServiceClient->createGlossary($formattedParent, $glossary);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'createGlossary');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
      $result = $newOperationResponse->getResult();
      // doSomethingWith($result)
    } else {
      $error = $newOperationResponse->getError();
      // handleError($error)
    }
} finally {
    $translationServiceClient->close();
}
public deleteGlossary( $name, array $optionalArgs = [])
 

Deletes a glossary, or cancels glossary construction
if the glossary isn't created yet.

Returns NOT_FOUND, if the glossary doesn't exist.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedName = $translationServiceClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]');
    $operationResponse = $translationServiceClient->deleteGlossary($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }


    // Alternatively:

    // start the operation, keep the operation name, and resume later
    $operationResponse = $translationServiceClient->deleteGlossary($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'deleteGlossary');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
      $result = $newOperationResponse->getResult();
      // doSomethingWith($result)
    } else {
      $error = $newOperationResponse->getError();
      // handleError($error)
    }
} finally {
    $translationServiceClient->close();
}
public detectLanguage( $parent, array $optionalArgs = [])
 

Detects the language of text within a request.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]');
    $response = $translationServiceClient->detectLanguage($formattedParent);
} finally {
    $translationServiceClient->close();
}
public getGlossary( $name, array $optionalArgs = [])
 

Gets a glossary. Returns NOT_FOUND, if the glossary doesn't
exist.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedName = $translationServiceClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]');
    $response = $translationServiceClient->getGlossary($formattedName);
} finally {
    $translationServiceClient->close();
}
public getOperationsClient()
 

Return an OperationsClient object with the same endpoint as $this.

  • return OperationsClient
  • experimental
public getSupportedLanguages( $parent, array $optionalArgs = [])
 

Returns a list of supported languages for translation.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]');
    $response = $translationServiceClient->getSupportedLanguages($formattedParent);
} finally {
    $translationServiceClient->close();
}
public static glossaryName( $project, $location, $glossary)
 

Formats a string containing the fully-qualified path to represent
a glossary resource.

  • return string The formatted glossary resource.
  • experimental
public listGlossaries( $parent, array $optionalArgs = [])
 

Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't
exist.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]');
    // Iterate over pages of elements
    $pagedResponse = $translationServiceClient->listGlossaries($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }


    // Alternatively:

    // Iterate through all elements
    $pagedResponse = $translationServiceClient->listGlossaries($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $translationServiceClient->close();
}
public static locationName( $project, $location)
 

Formats a string containing the fully-qualified path to represent
a location resource.

  • return string The formatted location resource.
  • experimental
public static parseName( $formattedName, $template = NULL)
 

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported:
Template: Pattern

  • glossary: projects/{project}/locations/{location}/glossaries/{glossary}
  • location: projects/{project}/locations/{location}.

The optional $template argument can be supplied to specify a particular pattern, and must
match one of the templates listed above. If no $template argument is provided, or if the
$template argument does not match one of the templates listed, then parseName will check
each of the supported templates, and return the first match.

  • return array An associative array from name component IDs to component values.
  • throws ValidationException If $formattedName could not be matched.
  • experimental
public resumeOperation( $operationName, $methodName = NULL)
 

Resume an existing long running operation that was previously started
by a long running API method. If $methodName is not provided, or does
not match a long running API method, then the operation can still be
resumed, but the OperationResponse object will not deserialize the
final response.

  • return OperationResponse
  • experimental
public translateText( $contents, $targetLanguageCode, $parent, array $optionalArgs = [])
 

Translates input text and returns translated text.

Sample code:

$translationServiceClient = new TranslationServiceClient();
try {
    $contents = [];
    $targetLanguageCode = '';
    $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]');
    $response = $translationServiceClient->translateText($contents, $targetLanguageCode, $formattedParent);
} finally {
    $translationServiceClient->close();
}
public static validate( $arr, $requiredKeys)
 
  • return array Returns $arr for fluent use
public static validateNotNull( $arr, $requiredKeys)
 
  • return array Returns $arr for fluent use
Methods
protected getCredentialsWrapper()
 

Get the credentials for the client. This method is protected to support
use by customized clients.

  • access private
  • return CredentialsWrapper
protected getTransport()
 

Get the transport for the client. This method is protected to support
use by customized clients.

  • access private
  • return TransportInterface
protected modifyClientOptions(array $options)
 

Modify options passed to the client before calling setClientOptions.

  • access private
protected modifyStreamingCallable(callable $callable)
 

Modify the streaming callable.

  • access private
protected modifyUnaryCallable(callable $callable)
 

Modify the unary callable.

  • access private
Properties
private $agentHeader
private $credentialsWrapper
private $descriptors
private static $gapicVersionFromFile
private static $glossaryNameTemplate
private static $locationNameTemplate
private $operationsClient
private static $pathTemplateMap
private $retrySettings
 
  • var RetrySettings[] $retrySettings
private $serviceName
private $transport
 
  • var TransportInterface
private $transportCallMethods
Methods
private arrayFilterRemoveNull(array $arr)
 

Just like array_filter(), but preserves falsey values except null.

  • return array
private buildClientOptions(array $options)
private buildMethod( $interfaceName, $methodName)
 
  • return string
private configureCallConstructionOptions( $methodName, array $optionalArgs)
 
  • return array
private createCallStack(array $callConstructionOptions)
 
  • return callable
private createCredentialsWrapper( $credentials, array $credentialsConfig)
 
  • return CredentialsWrapper
  • throws ValidationException
private createOperationsClient(array $options)
 
  • return OperationsClient
private createTransport( $apiEndpoint, $transport, array $transportConfig)
 
  • return TransportInterface
  • throws ValidationException
private static defaultTransport()
 
  • return string
private static getClientDefaults()
private static getGapicVersion(array $options)
private static getGlossaryNameTemplate()
private static getGrpcDependencyStatus()
 
  • return bool
private static getLocationNameTemplate()
private getPagedListResponse( $methodName, array $optionalArgs, $decodeType, Google\Protobuf\Internal\Message $request, $interfaceName = NULL)
 
  • return PagedListResponse
private static getPathTemplateMap()
private static initGrpcGcpConfig( $hostName, $confPath)
private isAssoc(array $arr)
 

Determine whether given array is associative.

  • return bool
private pluck( $key, array $arr, $isRequired = true)
 

Pluck a value out of an array.

  • return mixed|null
  • throws InvalidArgumentException
private pluckArray(array $keys, $arr)
 

Pluck a subset of an array.

  • return array
private setClientOptions(array $options)
 

Configures the GAPIC client based on an array of options.

  • throws ValidationException
private startCall( $methodName, $decodeType, array $optionalArgs = [], ?Google\Protobuf\Internal\Message $request = NULL, $callType = 0, $interfaceName = NULL)
 
  • return PromiseInterface|\BidiStream|\ClientStream|\ServerStream
private startOperationsCall( $methodName, array $optionalArgs, Google\Protobuf\Internal\Message $request, Google\ApiCore\LongRunning\OperationsClient $client, $interfaceName = NULL)
 
  • return PromiseInterface
private subsetArray(array $keys, $arr)
 

Return a subset of an array, like pluckArray, without modifying the original array.

  • return array
private static validateFileExists( $filePath)
 
  • throws ValidationException
private static validateGrpcSupport()
 
  • throws ValidationException
private static validateImpl( $arr, $requiredKeys, $allowNull)
Properties
private static $gapicVersionFromFile
private static $glossaryNameTemplate
private static $locationNameTemplate
private static $pathTemplateMap
public static $serviceScopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-translation']
 

The default scopes required by the service.

Methods
private static defaultTransport()
 
  • return string
private static getClientDefaults()
private static getGapicVersion(array $options)
private static getGlossaryNameTemplate()
private static getGrpcDependencyStatus()
 
  • return bool
private static getLocationNameTemplate()
private static getPathTemplateMap()
public static glossaryName( $project, $location, $glossary)
 

Formats a string containing the fully-qualified path to represent
a glossary resource.

  • return string The formatted glossary resource.
  • experimental
private static initGrpcGcpConfig( $hostName, $confPath)
public static locationName( $project, $location)
 

Formats a string containing the fully-qualified path to represent
a location resource.

  • return string The formatted location resource.
  • experimental
public static parseName( $formattedName, $template = NULL)
 

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported:
Template: Pattern

  • glossary: projects/{project}/locations/{location}/glossaries/{glossary}
  • location: projects/{project}/locations/{location}.

The optional $template argument can be supplied to specify a particular pattern, and must
match one of the templates listed above. If no $template argument is provided, or if the
$template argument does not match one of the templates listed, then parseName will check
each of the supported templates, and return the first match.

  • return array An associative array from name component IDs to component values.
  • throws ValidationException If $formattedName could not be matched.
  • experimental
public static validate( $arr, $requiredKeys)
 
  • return array Returns $arr for fluent use
private static validateFileExists( $filePath)
 
  • throws ValidationException
private static validateGrpcSupport()
 
  • throws ValidationException
private static validateImpl( $arr, $requiredKeys, $allowNull)
public static validateNotNull( $arr, $requiredKeys)
 
  • return array Returns $arr for fluent use
© 2020 Bruce Wells
Search Namespaces \ Classes
ConfigurationNumbers (0-9.) only