Weave 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 Translator Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Check installability first. The bundle targets Symfony 2.x/3.x and will almost certainly fail 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.
  2. Register the bundle in 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).
  3. Configure the API key. Expect a bundle config block roughly like:
# 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.

Implementation Patterns

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:

  • Group strings into a single request where the client supports it (the v2 endpoint accepts multiple q params; many thin wrappers don't expose this).
  • Cache by hash(text . source . target) in Redis or the DB with a long TTL — translations of a fixed string are effectively immutable.
  • Store the cache key alongside the source string so you can detect stale entries when the English copy changes.

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.

Gotchas and Tips

  • The bundle is dead. Last release 2017-09-26, 1 star, 0 dependents, no PHP 8 support, likely pinned to an ancient Guzzle. Any security or compatibility patch is yours to write. Budget for a fork or a replacement, not a "quick install."
  • API key ≠ credentials. The v2 "API key" mode is legacy-ish; Google is steering everyone to service-account credentials with the v3 API. If your org already uses ADC/service accounts, this bundle's key-based config is an awkward fit.
  • Billing is mandatory. You will get 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.
  • Quota and rate limits surface as generic 403/429s. The bundle almost certainly does not retry with backoff. Add a decorator that retries on 429/5xx with exponential backoff before you blame your code.
  • Silent failure on empty strings. Many thin wrappers return the input unchanged or throw on ''; guard your batch loop so one empty language key doesn't abort a 2,000-key import.
  • Character counting matters. You are billed on characters sent, including whitespace and markup. If you're translating a large lang/ tree, calculate the character count first (strlen over all values) and sanity-check the cost before running the job.
  • No translation memory or glossary. Proper nouns, product names, and brand terms will drift between runs and between locales. Maintain a do-not-translate list and post-process, or you'll get your product name localized into something unfortunate.
  • Debugging: read the bundle's service definition and translator class directly — there is no documentation beyond a short README, and the constructor signature is the only reliable contract. Log the raw request/response once (redacting the key) so you can tell a client bug from an API error.
  • Extension point you can actually use: because it's a Symfony service, you can decorate it. A decorator implementing the same interface, adding caching, retry, glossary substitution, and locale mapping, is where 90% of your real work will live — and it's the part that survives when you migrate off the bundle.
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.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle