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

Laravel Auto Translate Laravel Package

jeffersongoncalves/laravel-auto-translate

Automatically translate Laravel model attributes and content into multiple languages. Keeps localized fields in sync via translation services, cutting manual work for multilingual apps. Simple, Eloquent-friendly configuration makes setup quick and keeps your app ready for global users.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package with Composer and publish its config if the service provider exposes one:
    composer require <vendor>/<package>
    php artisan vendor:publish --tag=<package>-config
    
  2. Configure the MyMemory driver in config/<package>.php or the relevant environment variables. Set a contact email if the driver supports it — MyMemory grants a larger anonymous quota when a valid email is supplied.
  3. Look first at the package’s config file and service-provider bindings. That is where the translation driver, HTTP client, cache, and chunking behaviour are wired up.
  4. First use case: translate a single short string from a controller, artisan command, or job:
    $translated = app(Translator::class)->translate('Hello world', 'en', 'fr');
    
    Then move the same call into a queued job before translating anything in bulk.

Implementation Patterns

  • Wrap the package in your own translation service. Bind a small application-level class around the package’s translator. That keeps driver details, locale mapping, and retry logic out of controllers and models.
  • Queue bulk translation. Translation calls are external HTTP requests. Dispatch one job per document, paragraph, or locale pair, and use Laravel’s queue retry/backoff rather than translating synchronously in a request.
  • Pre-chunk long content at sentence or paragraph boundaries. Version 1.1.1 fixes the failure case where a single sentence exceeds MyMemory’s 450-byte request limit by splitting on words. That prevents exceptions, but splitting at natural sentence boundaries still produces better translations and avoids isolated word fragments.
  • Cache translated strings. Use Cache::remember() keyed by source text hash, source locale, target locale, and driver. This reduces quota usage and makes repeated page renders cheap.
  • Persist translations separately from source content. Store translations in a translations table or generated lang/ files. Do not overwrite the source column; keep both so you can re-run translation after source edits.
  • Integrate with model accessors or dedicated translation methods. For example, translate on model save via an observer that dispatches a job, then expose the translated value through an accessor with a fallback to the source locale.
  • Use Laravel’s HTTP client fakes in tests. Assert that long sentences are chunked and that requests stay under the byte limit. Test with multibyte source text, not only ASCII.
  • Respect locale and driver configuration. Keep source/target locale mapping in one place; MyMemory language codes may not match your application’s locale keys.

Gotchas and Tips

  • The 450-byte limit is bytes, not characters. Use strlen() when checking payload size, not mb_strlen(). Accented characters, CJK text, and emoji consume multiple bytes and can push a short-looking sentence over the limit.
  • The 1.1.1 fix is a patch-level behaviour change, not a breaking change. It replaces a hard failure with word-boundary splitting. Upgrade is safe, but review any code that relied on an exception being thrown for oversized input.
  • The fix handles a single over-limit sentence, but not translation quality. A long sentence split mid-thought may produce awkward target text. Pre-split at punctuation where possible.
  • Watch MyMemory quotas and rate limits. Anonymous usage is limited; configure a contact email and add application-level throttling. Handle HTTP 429 and 5xx responses with retries and backoff.
  • Do not translate inside loops without batching. Each call is an HTTP round trip. Group short strings where the driver supports it, or dispatch jobs in parallel with a queue worker pool.
  • Beware of config caching. After changing driver credentials, run php artisan config:clear. Stale cached config is a common cause of “why is it still using the old key?” debugging sessions.
  • Log request size and response status when debugging. A small custom middleware or wrapper around the package’s HTTP client makes byte-limit and quota issues visible. Log strlen($payload) alongside the source locale and target locale.
  • Use the package’s extension points rather than forking. If the driver or chunker is bound in the container, override it in a service provider. Prefer a custom driver implementation or a decorator around the translator over editing vendor code.
  • Test the boundary case explicitly. Include a unit test with a single sentence just under 450 bytes, one just over, and one containing multibyte characters. That guards against regressions in future patch releases.
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.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log