### Install SharpAPI PHP Content Text Translator via Composer Source: https://context7.com/sharpapi/php-content-text-translator/llms.txt Installs the SharpAPI PHP Content Text Translator package using Composer. This command adds the necessary libraries to your project for text translation capabilities. ```bash composer require sharpapi/php-content-text-translator ``` -------------------------------- ### Install SharpAPI PHP Content Text Translator via Composer Source: https://github.com/sharpapi/php-content-text-translator/blob/main/README.md This command installs the SharpAPI PHP Content Text Translator package using Composer, the dependency manager for PHP. Ensure you have Composer installed and configured in your project. ```bash composer require sharpapi/php-content-text-translator ``` -------------------------------- ### Initialize TextTranslatorClient in PHP Source: https://context7.com/sharpapi/php-content-text-translator/llms.txt Demonstrates how to create a new TextTranslatorClient instance in PHP. It shows basic initialization with an API key and advanced initialization with custom API base URL and user agent. ```php translateText( content: $content, toLanguage: 'Spanish', fromLanguage: 'English', voiceTone: 'informative', context: 'Environmental science article' ); echo "Translation job submitted.\n"; echo "Status URL: {$statusUrl}\n"; // Configure polling for longer content $client->setApiJobStatusPollingInterval(10); $client->setApiJobStatusPollingWait(180); // Fetch and process results $result = $client->fetchResults($statusUrl); $jsonResult = json_decode($result->getResultJson(), true); if ($jsonResult['data']['attributes']['status'] === 'success') { $translatedContent = $jsonResult['data']['attributes']['result']['content']; $targetLanguage = $jsonResult['data']['attributes']['result']['to_language']; echo "\nTranslation to {$targetLanguage}:\n"; echo $translatedContent; } } catch (GuzzleException $e) { echo "API error: " . $e->getMessage(); } ``` -------------------------------- ### Translate Text using SharpAPI PHP Client Source: https://github.com/sharpapi/php-content-text-translator/blob/main/README.md This snippet demonstrates how to use the TextTranslatorClient from the SharpAPI PHP package to translate text. It requires an API key and specifies the content, target language, and source language. The code also shows how to configure polling for job status and fetch the translated results, handling potential Guzzle HTTP exceptions. ```php translateText( content: 'Hello, world!', toLanguage: 'Spanish', fromLanguage: 'English' ); // Optional: Configure polling $client->setApiJobStatusPollingInterval(10); $client->setApiJobStatusPollingWait(180); // Fetch results (polls automatically) $result = $client->fetchResults($statusUrl); $resultData = $result->getResultJson(); echo $resultData; } catch (GuzzleException $e) { echo "API error: " . $e->getMessage(); } ``` -------------------------------- ### Translate Text Content using PHP SDK Source: https://context7.com/sharpapi/php-content-text-translator/llms.txt Translates text content from a source to a target language using the TextTranslatorClient in PHP. Supports optional voice tone and context parameters for enhanced translation quality. Returns a status URL for job tracking. ```php translateText( content: 'Hello, world! Welcome to our platform.', toLanguage: 'Spanish', fromLanguage: 'English' ); // Translation with voice tone for formal business content $statusUrl = $client->translateText( content: 'We are pleased to announce our new product line.', toLanguage: 'German', fromLanguage: 'English', voiceTone: 'formal' ); // Translation with additional context for better accuracy $statusUrl = $client->translateText( content: 'The bank was steep and muddy.', toLanguage: 'French', fromLanguage: 'English', voiceTone: null, context: 'This text is about hiking near a river' ); echo "Job submitted. Status URL: " . $statusUrl; } catch (GuzzleException $e) { echo "API error: " . $e->getMessage(); } ``` -------------------------------- ### Fetch Translation Results using PHP SDK Source: https://context7.com/sharpapi/php-content-text-translator/llms.txt Polls a status URL to retrieve completed translation results using the TextTranslatorClient in PHP. Allows configuration of polling intervals and wait times. Returns a result object containing the translated content. ```php translateText( content: 'The rise in sea levels threatens coastal communities worldwide.', toLanguage: 'French', fromLanguage: 'English' ); // Configure polling behavior $client->setApiJobStatusPollingInterval(10); // Check every 10 seconds $client->setApiJobStatusPollingWait(180); // Wait up to 180 seconds // Fetch results (polls automatically until complete) $result = $client->fetchResults($statusUrl); $resultData = $result->getResultJson(); echo $resultData; // Example response: // { // "data": { // "type": "api_job_result", // "id": "5de4887a-0dfd-49b6-8edb-9280e468c210", // "attributes": { // "status": "success", // "type": "content_translate", // "result": { // "content": "La montée du niveau des mers menace les communautés côtières du monde entier.", // "to_language": "French", // "from_language": "English" // } // } // } // } } catch (GuzzleException $e) { echo "API error: " . $e->getMessage(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.