PHPackages                             pollora/pollingo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pollora/pollingo

ActiveLibrary

pollora/pollingo
================

A PHP package for translating strings using AI

v1.4(11mo ago)182MITPHPPHP ^8.2|^8.3CI failing

Since Mar 25Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/Pollora/Pollingo)[ Packagist](https://packagist.org/packages/pollora/pollingo)[ RSS](/packages/pollora-pollingo/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (15)Versions (6)Used By (0)

[![Logo Laravel Pollingo](public/logo.svg)](public/logo.svg)

🌍 Pollingo
==========

[](#-pollingo)

A framework-agnostic PHP package for translating groups of strings using OpenAI.

🚀 Features
----------

[](#-features)

- ✨ Fluent API for submitting groups of strings to translate
- 🔤 Simple API for translating single strings
- 🤖 OpenAI-powered smart, contextual translations
- 🔌 Support for custom translation providers
- 🌐 Global and per-string context support
- 🔤 Support for all ISO 639-1 language codes
- 📦 Framework-agnostic with Laravel integration
- 🧩 Modular architecture for easy extension with other AI providers

📥 Installation
--------------

[](#-installation)

### Standalone Installation

[](#standalone-installation)

```
composer require pollora/pollingo
```

### Laravel Installation

[](#laravel-installation)

The package will automatically register itself if you're using Laravel's package discovery. After installation, you can publish the configuration file:

```
php artisan vendor:publish --tag=pollingo-config
```

🔧 Configuration
---------------

[](#-configuration)

### Standalone Configuration

[](#standalone-configuration)

Set your OpenAI API key in your environment:

```
OPENAI_API_KEY=your-api-key
OPENAI_MODEL=gpt-4
```

### Laravel Configuration

[](#laravel-configuration)

In your `.env` file:

```
OPENAI_API_KEY=your-api-key
OPENAI_MODEL=gpt-4
```

You can also customize the configuration in `config/pollingo.php` after publishing it.

📝 Basic Usage
-------------

[](#-basic-usage)

### Single String Translation

[](#single-string-translation)

```
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();
```

### Group Translation

[](#group-translation)

```
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();
```

### Laravel Usage

[](#laravel-usage)

Using the Facade:

```
use Pollora\Pollingo\Facades\Pollingo;

$translations = Pollingo::from('en')
    ->to('fr')
    ->group('messages', [
        'welcome' => 'Welcome to our application',
        'goodbye' => 'Goodbye!',
    ])
    ->translate();
```

Using Dependency Injection:

```
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();
    }
}
```

🌐 Language Support
------------------

[](#-language-support)

Pollingo supports all ISO 639-1 language codes. Here are some common examples:

- 🇺🇸 English: `en`
- 🇫🇷 French: `fr`
- 🇪🇸 Spanish: `es`
- 🇩🇪 German: `de`
- 🇮🇹 Italian: `it`
- 🇯🇵 Japanese: `ja`
- 🇨🇳 Chinese: `zh`
- 🇷🇺 Russian: `ru`

Example with language codes:

```
$pollingo
    ->from('en')    // Source language (English)
    ->to('fr')      // Target language (French)
    ->translate();
```

🧩 Advanced Features
-------------------

[](#-advanced-features)

### Groups and Context

[](#groups-and-context)

You can organize your translations into logical groups and provide context:

```
$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'
    ]
]);
```

### Custom Translators

[](#custom-translators)

While OpenAI is the default translation provider, you can implement your own translator by implementing the `Translator` interface:

```
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
    }
}
```

You can then use your custom translator in two ways:

1. Using the fluent `withTranslator()` method:

```
$pollingo = Pollingo::make()
    ->withTranslator(new MyCustomTranslator())
    ->from('en')
    ->to('fr')
    ->translate();
```

2. Using the `make()` method's `translator` parameter:

```
$pollingo = Pollingo::make(translator: new MyCustomTranslator());
```

This is particularly useful when you want to:

- Use a different translation service (DeepL, Google Translate, etc.)
- Implement custom translation logic
- Mock translations for testing
- Cache translations
- Implement fallback mechanisms

### Creating Custom AI Translators

[](#creating-custom-ai-translators)

You can create custom AI translators by extending the `BaseAITranslator` class:

```
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();
    }
}
```

### Global Context

[](#global-context)

You can provide global context that applies to all translations:

```
$pollingo
    ->withGlobalContext('This is for a professional business application')
    ->group('auth', [
        'login' => 'Log in',
        'register' => 'Create an account',
    ])
    ->translate();
```

### Multiple Groups

[](#multiple-groups)

You can translate multiple groups in a single request:

```
$translations = $pollingo
    ->from('en')
    ->to('fr')
    ->group('ui', [
        'save' => 'Save',
        'cancel' => 'Cancel',
    ])
    ->group('messages', [
        'success' => 'Operation completed successfully',
        'error' => 'An error occurred',
    ])
    ->translate();
```

🛠️ Laravel Integration Features
-------------------------------

[](#️-laravel-integration-features)

### Configuration

[](#configuration)

The package provides a configuration file that can be customized:

```
// config/pollingo.php
return [
    'openai' => [
        'api_key' => env('OPENAI_API_KEY'),
        'model' => env('OPENAI_MODEL', 'gpt-4'),
    ],
];
```

### Service Container

[](#service-container)

The package registers both the main service and the translator interface in Laravel's service container:

```
use Pollora\Pollingo\Contracts\Translator;

class TranslationService
{
    public function __construct(
        private readonly Translator $translator
    ) {}
}
```

### API Configuration and Reliability

[](#api-configuration-and-reliability)

Pollingo provides methods to customize the OpenAI API configuration and enhance reliability with retries:

```
// Select different AI models for different needs
$translations = Pollingo::make('your-openai-api-key')
    ->model('gpt-4.1-nano')  // Smaller, faster model for simple translations
    ->from('en')
    ->to('fr')
    ->text('Hello world')
    ->translate();

// Set custom timeout for long translations
$translations = Pollingo::make('your-openai-api-key')
    ->timeout(180)  // 3 minutes timeout (default: 120 seconds)
    ->from('en')
    ->to('es')
    ->group('legal', $legalTexts)  // Large legal documents
    ->translate();

// Configure retry behavior
$translations = Pollingo::make('your-openai-api-key')
    ->maxRetries(5)           // Number of retries on failure (default: 3)
    ->retryDelay(2000)        // Milliseconds between retries (default: 1000)
    ->from('en')
    ->to('ja')
    ->group('documents', $documents)
    ->translate();

// Chain configuration methods
$translations = Pollingo::make('your-openai-api-key')
    ->model('gpt-4.1-turbo')
    ->timeout(240)
    ->maxRetries(4)
    ->retryDelay(1500)
    ->from('en')
    ->to('zh')
    ->group('marketing', $marketingContent)
    ->translate();
```

🧪 Testing
---------

[](#-testing)

```
composer test
```

For testing with OpenAI, you need to set the following environment variables:

```
OPENAI_API_KEY=your-api-key OPENAI_MODEL=gpt-4 vendor/bin/pest
```

🤝 Contributing
--------------

[](#-contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance50

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Total

5

Last Release

357d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b45e81c070e2ec0baf59b2a73a216632d76cdfb36c0ab168fd6d043b2c8fbc2?d=identicon)[pollora](/maintainers/pollora)

---

Top Contributors

[![ogorzalka](https://avatars.githubusercontent.com/u/149651?v=4)](https://github.com/ogorzalka "ogorzalka (10 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pollora-pollingo/health.svg)

```
[![Health](https://phpackages.com/badges/pollora-pollingo/health.svg)](https://phpackages.com/packages/pollora-pollingo)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
