zeliard91/google-translator-bundle
A Symfony bundle that integrates Google Translate into your application, exposing a simple service for translating text between languages and configuration options to wire it into your project quickly.
This is a Symfony bundle, not a Laravel package, and it has been unmaintained since its single 2017 release. Before writing any code, decide whether you are adopting it or just mining it for ideas — with 1 star, 0 dependents, and no release in 8 years, the realistic outcome for most teams is "read the source, then use the official Google client instead."
If you still want to try it:
composer require on PHP 8 or Symfony 5+. Run the require in a throwaway branch and read the conflict report before planning anything around it.app/AppKernel.php (Symfony 2/3 style — there is no Laravel service provider, so a Laravel integration means writing your own provider that binds the underlying translator class into the container).# app/config/config.yml
pryon_google_translator:
api_key: "%google_translate_api_key%"
The key comes from Google Cloud Console with the Cloud Translation API (v2) enabled and billing attached — there is no free tier key.
4. Look at the service definition first, not the README. Resources/config/services.yml inside the bundle tells you the real service ID and constructor arguments; the docs are thin and the service ID is what you actually need.
5. First use case: translate a single string in a controller/console command to prove credentials work, e.g. en → es on a hardcoded sentence. Do not start with your lang/ files.
// Symfony-style, inside a controller
$translated = $this->get('pryon_google_translator.translator')
->translate('Hello world', 'es', 'en'); // verify argument order in the source
For a Laravel codebase, the pragmatic equivalent is google/cloud-translate (official, maintained) or stichoza/google-translate-php (unofficial, scrapes the free endpoint). Treat this bundle as documentation of the API shape, not as a dependency.
Wrap the translator behind your own interface. Never let the bundle's service leak into controllers or jobs. One Translator contract with translate(string $text, string $to, ?string $from = null): string lets you swap the 2017 bundle for the official client later without touching call sites.
interface Translator
{
public function translate(string $text, string $to, ?string $from = null): string;
}
Translate keys, not rendered strings. Run translation over your lang/en/*.php (or JSON) values in a one-off Artisan/console command, write the results back to lang/{locale}/, and commit them. Machine translation at request time is slow, costs money per character, and makes output non-deterministic under cache misses.
Batch and cache aggressively. Google bills per character, so:
q params; many thin wrappers don't expose this).hash(text . source . target) in Redis or the DB with a long TTL — translations of a fixed string are effectively immutable.Locale mapping is your job. Google expects en, es, pt-BR, zh-CN; your app may use en_GB or pt_BR. Keep an explicit map (pt_BR => pt-BR) rather than passing raw app locales through — the API silently falls back to something odd on unrecognized codes.
Async for anything user-facing. Queue translation jobs (Laravel ShouldQueue / Symfony message bus) when you must translate user-generated content, and translate on write, not on read. Add a translated_at column so you can backfill missing locales with a scheduled command instead of on demand.
HTML and placeholders. If you send HTML, the API will happily mangle attributes; if you send :name or {{ $count }} placeholders, expect them to come back translated or reordered. Either translate plain text only, or strip/reinsert placeholders around the call.
403 with a billing-related message if the project has no billing account. This is the single most common first-run failure and it looks like an auth error.''; guard your batch loop so one empty language key doesn't abort a 2,000-key import.lang/ tree, calculate the character count first (strlen over all values) and sanity-check the cost before running the job.How can I help you explore Laravel packages today?