1. Go to this page and download the library: Download pollora/pollingo 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/ */
pollora / pollingo example snippets
use Pollora\Pollingo\Pollingo;
// Simple translation
$translation = Pollingo::make('your-openai-api-key')
->from('en')
->to('fr')
->text('Welcome to our application')
->translate();
// Translation with context
$translation = Pollingo::make('your-openai-api-key')
->from('en')
->to('fr')
->text('Welcome to our platform!')
->context('Used in the subject of a welcome email.')
->translate();
use Pollora\Pollingo\Pollingo;
$translations = Pollingo::make('your-openai-api-key')
->from('en')
->to('fr')
->group('messages', [
'welcome' => 'Welcome to our application',
'goodbye' => 'Goodbye!',
])
->translate();
use Pollora\Pollingo\Facades\Pollingo;
$translations = Pollingo::from('en')
->to('fr')
->group('messages', [
'welcome' => 'Welcome to our application',
'goodbye' => 'Goodbye!',
])
->translate();
use Pollora\Pollingo\Pollingo;
class TranslationController
{
public function __construct(
private readonly Pollingo $pollingo
) {}
public function translate()
{
return $this->pollingo
->from('en')
->to('fr')
->group('messages', [
'welcome' => 'Welcome to our application',
])
->translate();
}
}
$pollingo
->from('en') // Source language (English)
->to('fr') // Target language (French)
->translate();
$pollingo->group('emails', [
'welcome' => [
'text' => 'Welcome to our platform!',
'context' => 'Used in the subject of a welcome email.'
],
'greeting' => [
'text' => 'Hi {name}',
'context' => 'Personal greeting with user name placeholder'
]
]);
use Pollora\Pollingo\Contracts\Translator;
class MyCustomTranslator implements Translator
{
public function translate(
array $groups,
string $targetLanguage,
?string $sourceLanguage = null,
?string $globalContext = null
): array {
// Your custom translation logic here
}
}
$pollingo = Pollingo::make(translator: new MyCustomTranslator());
use Pollora\Pollingo\Services\BaseAITranslator;
use Pollora\Pollingo\Contracts\AIClient;
class GoogleAITranslator extends BaseAITranslator implements AIClient
{
private readonly GoogleClient $client;
public function __construct(
string $apiKey,
string $model = 'gemini-pro',
int $timeout = 120
) {
parent::__construct($model, $timeout);
$this->client = new GoogleClient($apiKey);
}
public function translate(array $groups, string $targetLanguage, ?string $sourceLanguage = null, ?string $globalContext = null): array
{
// Implementation for Google AI translation
}
public function chatCompletion(string $model, array $messages, float $temperature = 0.1): string
{
// Implementation for Google AI chat completion
}
protected function getSystemPrompt(): string
{
// Optionally override the system prompt for Google AI
return parent::getSystemPrompt();
}
}
$pollingo
->withGlobalContext('This is for a professional business application')
->group('auth', [
'login' => 'Log in',
'register' => 'Create an account',
])
->translate();