Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Google Translate Php Laravel Package

stichoza/google-translate-php

Free, unofficial Google Translate API client for PHP 8+. Translate text between languages with simple methods, auto language detection, supported languages list, parameter preservation, raw responses, custom URL/token generator, and configurable HTTP client.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require stichoza/google-translate-php. The package provides a simple, static-based translator class with no configuration needed for basic usage. Start by instantiating the translator: $translator = new Stoichoza\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.

Implementation Patterns

  • Use caching (e.g., with Laravel’s cache facade) around translate() calls to avoid repeated network requests for identical text.
  • Wrap the translator in a service class to abstract language handling and improve testability (e.g., TranslationService::translateText($text, $to, $from = null)).
  • In Laravel, bind the translator in a service provider and inject it where needed instead of static calls.
  • Use batch translation via looping or async handling (e.g., Horizon jobs) for large volumes—note the API has rate limits and may throttle.
  • Leverage environment variables or config files to manage fallback languages, default locales, and API override strategies (though the package itself uses no configurable API key—it's true free usage).

Gotchas and Tips

  • Unreliable under load: This package uses the unofficial Google Translate frontend, so it's subject to change, blocks, or rate-limiting without warning. Monitor for 403/503 responses and implement retry logic.
  • Language detection may return auto or be inaccurate for short text—always validate detected results in sensitive workflows.
  • The package doesn’t support translating HTML directly—strip or escape tags before translation to avoid corruption; consider using a post-process to reinsert HTML safely.
  • No official support for Google Translate’s advanced options (e.g., formality, glossaries). For production-grade translation, consider migrating to the official Google Cloud Translation API when scalability is needed.
  • To debug, inspect $translator->getLastResponse() or catch GuzzleHttp\Exception\RequestException to capture HTTP-level issues.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport