Translate final Laravel and Blade HTML safely with route exclusions, CSRF preservation, source-aware caching, asset freshness, and localized SEO.
Choose the translation source at the response boundary
For a Blade application, the most complete source is often the final HTML response after controllers, views, components, and middleware have produced the page. Translating that response avoids running a separate browser renderer for content that already exists on the server. It also captures text generated by shared layouts and packages.
Only process eligible successful HTML responses. Skip JSON, files, redirects, streams, private dashboards, and non-idempotent requests. Define explicit route exclusions for authentication, administration, payment, and other sensitive areas.
Select translatable content safely
Parse HTML with a maintained parser and translate text nodes and approved attributes such as titles, descriptions, placeholders, and accessible labels. Exclude scripts, styles, code examples, user input, tokens, product identifiers, and elements marked with a no-translate attribute. Never use regular expressions as the primary HTML parser.
Preserve form actions, CSRF tokens, route parameters, signed URLs, and application state. Translation must not change identifiers or turn a safe URL into an unsupported protocol. Sanitize only where the application intentionally accepts rich user content; ordinary translated text should remain escaped.
Cache by page identity and source version
Build cache keys from the normalized page, target language, rendering policy, and a source content hash. Reuse completed translations when the source has not changed, and keep incomplete or failed results out of the public cache. A shared package path prevents each Laravel application from inventing a different freshness rule.
Invalidate translated HTML when templates or content change. Asset deployment can also matter: cached HTML that references removed Vite assets will render without styles even when the translation itself is correct. Coordinate response cache freshness with the frontend build revision.
