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

Laravel Localization Laravel Package

shureban/laravel-localization

Laravel middleware that auto-sets the application locale from the HTTP Accept-Language header. Install via Composer, register the service provider, and add the Localization middleware globally, per group, or per route.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Globalization/Internationalization (G11N/i18n) Roadmap: Accelerates the rollout of multilingual support for a product targeting non-English markets (e.g., EU, Latin America, or Asia). Reduces dev effort for manual locale switching and translation management.
  • Build vs. Buy: Buy—avoids reinventing locale detection, fallback logic, and middleware for HTTP Accept-Language headers. Lowers technical debt compared to custom solutions.
  • Use Cases:
    • Automatic Locale Detection: Dynamically sets the app’s locale based on user browser preferences (e.g., Accept-Language: en-US, es-MX).
    • Route Localization: Enables URL paths like /en/about or /es/contacto without custom routing logic.
    • Fallback Mechanisms: Handles unsupported locales gracefully (e.g., default to en if zh-Hant translations are missing).
    • API Localization: Standardizes locale headers in responses for frontend frameworks (e.g., React/Vue) to render content in the user’s language.
  • Feature Prioritization:
    • Phase 1: Integrate middleware for automatic locale detection (MVP for global audiences).
    • Phase 2: Extend to route-based localization (e.g., /:locale/...) for SEO and user experience.
    • Phase 3: Add user preference overrides (e.g., dashboard settings to force a locale).

When to Consider This Package

  • Adopt If:

    • Your Laravel app lacks a unified locale detection system and relies on manual overrides (e.g., ?locale=es query params).
    • You need zero-configuration multilingual support for existing routes/views without rewriting middleware.
    • Your team prioritizes developer velocity over customization (e.g., no need for complex fallback rules or database-backed locales).
    • You’re targeting browser-based audiences where Accept-Language headers are reliable (e.g., web apps, not mobile apps with forced locales).
    • Your Laravel version is 8+ (verify compatibility; v1.0.0 may not support Laravel 10+).
  • Look Elsewhere If:

    • You require database-driven translations (e.g., CMS-like content management for locales). Consider spatie/laravel-translatable or laravel-localization (note: different package).
    • Your app needs server-side locale persistence (e.g., user accounts with saved language preferences). This package focuses on request-level detection, not storage.
    • You’re building a mobile app where Accept-Language headers are unreliable (e.g., iOS/Android may ignore them). Use platform-specific APIs instead.
    • You need advanced features like:
      • Right-to-left (RTL) language support (e.g., Arabic, Hebrew) with CSS/HTML adjustments.
      • Machine translation APIs (e.g., Google Translate integration).
      • Locale-specific content delivery (e.g., geo-blocking or CDN rules).
    • Your team lacks Laravel middleware experience—this package requires adding middleware to the kernel.
    • You’re using non-Laravel frontend frameworks (e.g., Next.js, SvelteKit) where locale logic should live in the frontend.

How to Pitch It (Stakeholders)

For Executives (Business Case)

*"This package lets us ship multilingual support in weeks, not months, by automating locale detection from user browsers. For example:

  • A Spanish visitor to our EU site will see content in Spanish without manual intervention.
  • SEO improves with localized URLs (e.g., /es/blog).
  • Dev effort shifts from building custom middleware to testing and scaling the solution. Risk: Minimal—it’s a lightweight middleware with MIT licensing. We’ll pilot it in staging first to validate performance and edge cases (e.g., unsupported languages)."*

ROI:

  • Speed: Reduces dev time by 70% vs. custom implementation.
  • Scale: Supports 100+ languages with zero additional backend work.
  • Cost: Free (MIT license), no vendor lock-in.

For Engineering (Technical Summary)

*"This is a Laravel middleware package that sets the app’s locale dynamically based on the HTTP Accept-Language header. Key benefits:

  • Plug-and-play: Add one line to app/Http/Kernel.php to enable automatic locale detection.
  • Flexible: Works globally, per-route, or per-group (e.g., only for API routes).
  • Lightweight: No database or heavy dependencies—just middleware and config.
  • Extensible: Supports custom fallback logic via published config.

How We’ll Use It:

  1. MVP: Replace manual ?locale=es params with automatic detection for all web routes.
  2. Phase 2: Add route-based localization (e.g., /:locale/...) for SEO.
  3. Future: Integrate with frontend (e.g., pass locale to React via API headers).

Risks:

  • Compatibility: Verify with Laravel 10+ (v1.0.0 may need updates).
  • Edge Cases: Test RTL languages and unsupported locales.
  • Performance: Middleware adds ~1ms latency (negligible for most apps).

Next Steps:

  • Install in staging: composer require shureban/laravel-localization.
  • Publish config: php artisan vendor:publish --provider="Shureban\LaravelLocalization\LocalizationServiceProvider".
  • Test with Accept-Language headers in Postman/cURL.
  • Roll out to a non-critical module first (e.g., blog)."*
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle