Download the PHP package pollora/pollingo without Composer
On this page you can find all versions of the php package pollora/pollingo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pollora/pollingo
More information about pollora/pollingo
Files in pollora/pollingo
Package pollingo
Short Description A PHP package for translating strings using AI
License MIT
Informations about the package pollingo
๐ Pollingo
A framework-agnostic PHP package for translating groups of strings using OpenAI.
๐ 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
Standalone 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:
๐ง Configuration
Standalone Configuration
Set your OpenAI API key in your environment:
Laravel Configuration
In your .env file:
You can also customize the configuration in config/pollingo.php after publishing it.
๐ Basic Usage
Single String Translation
Group Translation
Laravel Usage
Using the Facade:
Using Dependency Injection:
๐ 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:
๐งฉ Advanced Features
Groups and Context
You can organize your translations into logical groups and provide context:
Custom Translators
While OpenAI is the default translation provider, you can implement your own translator by implementing the Translator interface:
You can then use your custom translator in two ways:
-
Using the fluent
withTranslator()method: - Using the
make()method'stranslatorparameter:
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
You can create custom AI translators by extending the BaseAITranslator class:
Global Context
You can provide global context that applies to all translations:
Multiple Groups
You can translate multiple groups in a single request:
๐ ๏ธ Laravel Integration Features
Configuration
The package provides a configuration file that can be customized:
Service Container
The package registers both the main service and the translator interface in Laravel's service container:
API Configuration and Reliability
Pollingo provides methods to customize the OpenAI API configuration and enhance reliability with retries:
๐งช Testing
For testing with OpenAI, you need to set the following environment variables:
๐ค Contributing
Please see CONTRIBUTING.md for details.
๐ License
The MIT License (MIT). Please see License File for more information.
All versions of pollingo with dependencies
nyholm/psr7 Version ^1.8
openai-php/client Version ^0.8.0
patrickschur/language-detection Version ^5.0
symfony/http-client Version ^6.0|^7.0
vlucas/phpdotenv Version ^5.6
guzzlehttp/guzzle Version ^7.0