laravel-google-informal-icu-i18n-translate
Adds the free Google Translate provider (eugene-erg/google-informal-icu-i18n-translator) to the Laravel translator (eugene-erg/laravel-icu-i18n-translate). Install it and the translator fills missing translations through Google. No API key is needed.
The informal endpoint has no SLA and can change or rate-limit at any time. Use it for development and drafts, and put a reliable provider before it for production.
composer require eugene-erg/laravel-google-informal-icu-i18n-translate
php artisan migrate # the tables of laravel-icu-i18n-translateRequires PHP 8.3+, Laravel 13 and ext-intl. Both service providers are discovered automatically.
use EugeneErg\IcuI18nTranslator\Translator;
$translator = app(Translator::class);
$translator->translateMessage('Hello, {name}!', ['name' => 'Ivan'], toLocale: 'ru', fromLocale: 'en');
// "Привет, Ivan!": translated once, then read from the databaseFiles, formats and everything else are described in laravel-icu-i18n-translate and the core translator.
Configuration
The endpoint, for a proxy (config/services.php):
'google_informal_translate' => [
'url' => env('GOOGLE_INFORMAL_TRANSLATE_URL', 'https://translate.googleapis.com'),
],HTTP goes through Guzzle, and the list of Google languages is cached for a day in the default Laravel cache. Bind your own Psr\Http\Client\ClientInterface, PSR-17 factories or Psr\SimpleCache\CacheInterface to replace them.
Google is added at the end of TranslatorInterface::class . '[]'. To put another provider first:
$this->app->extend(TranslatorInterface::class . '[]', fn (array $translators) => [new MyProvider(), ...$translators]);Upgrading to 2.x
- Requires
eugene-erg/laravel-icu-i18n-translate3.x or 4.x andeugene-erg/google-informal-icu-i18n-translator3.x (namedgoogle-informal-icu-i18n-translateup to 2.x). 1.x could not be installed with them. - The endpoint is read from
config('services.google_informal_translate.url'). 1.x read a config key namedGOOGLE_ICU_I18N_TRANSLATE_API_URL, which no config file defines. - The service provider is now discovered automatically (1.x declared it outside
extra). - Guzzle is a dependency instead of an optional default.
Development
composer check # pint, phpstan (level max), phpunitFrom the README.md of EugeneErg/laravel-google-informal-icu-i18n-translate · composer require eugene-erg/laravel-google-informal-icu-i18n-translate