stichoza/google-translate-php
Free Google Translate API wrapper for PHP (8.0+). Translate text between languages, detect languages, preserve parameters, and customize HTTP clients or token generators—no API key required. Installed via Composer.
Install via Composer: composer require stichoza/google-translate-php (pin ^5.3.5 or later—see Gotchas for the emoji/token fix). The package provides a simple, static-based translator class with no configuration needed for basic usage. Start by instantiating the translator: $translator = new Stichoza\GoogleTranslate\TranslateClient();, then translate text: $translated = $translator->translate('Hello world', 'es');. The first argument is the text, the second is the target language code (ISO 639-1). For detecting language, use $translator->detect('Hola mundo');. Check the README.md in the repo for full list of supported languages and examples.
translate() calls to avoid repeated network requests for identical text.TranslationService::translateText($text, $to, $from = null)).'Hello 👋') if your content pipeline accepts user-generated text; token generation for such input is exactly what v5.3.5 repaired, so a test locks in the behaviour across future upgrades.5.3.5 if you translate user-generated content, social copy, or chat messages.auto or be inaccurate for short text—always validate detected results in sensitive workflows.$translator->getLastResponse() or catch GuzzleHttp\Exception\RequestException to capture HTTP-level issues. When a translation fails only for certain inputs, log the raw source string (with encoding) before assuming an API outage—malformed tokens are an input-dependent failure mode, not a transient one.How can I help you explore Laravel packages today?