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

Spatie Laravel Translatable Plugin Laravel Package

filament/spatie-laravel-translatable-plugin

Filament v3 plugin integrating spatie/laravel-translatable into resources: set default locales, mark models as translatable, add Translatable traits to resources and pages, and use a LocaleSwitcher action to edit content per locale. Now maintained by Lara Zeus.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Multi-language Content Support: The package extends Filament’s admin panel to natively support spatie/laravel-translatable, enabling seamless management of multilingual models (e.g., CMS pages, product descriptions, or localized content). This aligns well with applications requiring i18n without manual JSON/XML handling.
  • Filament Ecosystem Synergy: Leverages Filament’s existing UI components (e.g., tables, forms) to expose translatable fields without reinventing the wheel. Reduces frontend/backend coupling by abstracting localization logic into a plugin.
  • Database Agnostic: Works with Eloquent’s translatable trait, so no schema changes are required beyond the base model setup. Compatible with MySQL, PostgreSQL, etc.
  • Limitation: Primarily a UI layer enhancement—does not handle translation storage/validation at the API level (e.g., REST endpoints). Requires complementary backend logic (e.g., spatie/laravel-translatable + custom API routes).

Integration Feasibility

  • Low-Coupling: Plugin-based design means minimal core code changes. Can be added to existing Filament projects with minimal risk.
  • Dependency Overlap: Requires spatie/laravel-translatable (v3.x+) and Filament v3.x. Version conflicts unlikely if the stack is modern.
  • Customization: Supports overriding default behavior via Filament’s plugin hooks (e.g., modifyTranslatableFields). Extensible for edge cases (e.g., fallback locales, custom validation).

Technical Risk

  • Locale-Specific Validation: Translatable fields may need locale-aware validation (e.g., length per language). Requires explicit handling in Filament forms.
  • Performance: Large translatable models (e.g., 10+ languages) could bloat queries if not optimized. Mitigate with:
    • Database indexing on locale columns.
    • Lazy-loading translations via withTranslations().
  • Testing: Edge cases like:
    • Concurrent edits to the same translatable field.
    • Locale-specific business logic (e.g., currency formatting). Requires comprehensive UI/integration tests.

Key Questions

  1. Locale Strategy:
    • How are locales managed (hardcoded, user-selected, or dynamic)?
    • Is fallback logic needed (e.g., default to en if fr is missing)?
  2. Data Volume:
    • Expected number of languages/translations per record?
    • Are there plans for translation caching (e.g., Redis)?
  3. API Consistency:
    • Should translatable fields be exposed via REST/GraphQL? If so, how will the plugin interact with API resources?
  4. User Experience:
    • Will editors need to switch locales frequently? Consider a locale picker UI.
    • Are there non-Filament interfaces (e.g., frontend) that need synchronized translations?

Integration Approach

Stack Fit

  • Primary Use Case: Ideal for Filament-based admin panels managing multilingual content (e.g., SaaS platforms, e-commerce, global CMS).
  • Complementary Tools:
    • Backend: spatie/laravel-translatable (v3.x) for Eloquent models.
    • Frontend: Laravel Mix/Vite for locale-specific assets (e.g., JS/CSS).
    • Localization: laravel-localization or mcpowermts/laravel-localization for frontend routing.
  • Anti-Patterns:
    • Avoid for high-frequency translation updates (e.g., real-time chat) without caching.
    • Not a replacement for dedicated translation services (e.g., Crowdin, Lokalise) for workflows.

Migration Path

  1. Prerequisites:
    • Install spatie/laravel-translatable and configure models:
      composer require spatie/laravel-translatable
      php artisan vendor:publish --provider="Spatie\Translatable\TranslatableServiceProvider"
      
    • Add translatable fields to Eloquent models:
      use Spatie\Translatable\HasTranslations;
      
      class Page extends Model implements HasTranslations {
          public $translatable = ['title', 'content'];
      }
      
  2. Filament Plugin Setup:
    • Install the plugin:
      composer require filament/spatie-laravel-translatable-plugin
      
    • Register in app/Providers/Filament/AdminPanelProvider.php:
      public function panel(Panel $panel): Panel {
          return $panel
              ->plugins([
                  \FilamentSpatieTranslatablePlugin::make(),
              ]);
      }
      
  3. Resource Integration:
    • Extend Filament resources to expose translatable fields:
      use Filament\Forms\Components\TextInput;
      use FilamentSpatieTranslatablePlugin\Forms\Components\TranslatableTextInput;
      
      public static function form(Form $form): Form {
          return $form->schema([
              TranslatableTextInput::make('title')->required(),
              TranslatableTextInput::make('content')->rows(5),
          ]);
      }
      
  4. Testing:
    • Validate CRUD operations for translatable fields.
    • Test locale switching and fallback behavior.

Compatibility

  • Filament Version: Tested with Filament v3.x. May require adjustments for v2.x.
  • PHP Version: Requires PHP 8.0+. Check for compatibility with older stacks.
  • Database: No schema migrations needed, but ensure locale column exists (handled by spatie/laravel-translatable).
  • Custom Fields: Plugin supports basic field types (text, rich text). Complex fields (e.g., relationships) may need manual implementation.

Sequencing

  1. Phase 1: Implement core translatable models and basic Filament integration.
  2. Phase 2: Add locale-specific validation and UI enhancements (e.g., locale toggles).
  3. Phase 3: Extend to API layers (if needed) and optimize performance (e.g., caching).
  4. Phase 4: Roll out to production with A/B testing for multilingual workflows.

Operational Impact

Maintenance

  • Plugin Updates: Monitor filament/spatie-laravel-translatable-plugin for Filament v3.x compatibility. Minor updates likely low-risk.
  • Dependency Management:
    • spatie/laravel-translatable: Critical for backend logic. Major version bumps may require testing.
    • Filament core updates could break plugin functionality (e.g., if UI components change).
  • Documentation: Limited official docs; rely on GitHub issues and Filament’s ecosystem for troubleshooting.

Support

  • Debugging:
    • Common issues: Missing translations, locale conflicts, or form rendering bugs.
    • Tools: Laravel Telescope for query logging, Filament’s debug panel.
  • Community: Active Filament/Spatie communities on GitHub/Discord. Expect faster support for Filament-related issues.
  • Fallback Plan: For critical issues, revert to manual translatable field handling or use Filament’s raw form components.

Scaling

  • Database Load:
    • Risk: High-cardinality locales (e.g., 20+ languages) may slow queries. Mitigate with:
      • Database indexing on locale and translatable_key columns.
      • Query scoping (e.g., withTranslations(['en', 'fr'])).
    • Solution: Consider a dedicated translations table with proper indexing.
  • Caching:
    • Cache translated content at the application level (e.g., Redis) for read-heavy workloads.
    • Example: Use spatie/laravel-caching to cache translations per locale.
  • Horizontal Scaling: Stateless plugin design means it scales with Filament’s architecture. No additional infrastructure needed.

Failure Modes

Failure Scenario Impact Mitigation
Plugin conflicts with Filament core UI breaks or translatable fields disappear Test with Filament’s latest stable version.
Missing translations in production Inconsistent user experience Implement fallback locales and alerts.
Database timeouts on large datasets Slow admin panel Optimize queries, paginate translatable fields.
Locale-specific validation errors Data corruption or rejected edits Add explicit validation per locale.
Plugin not updating with Filament Feature drift Pin versions or contribute to plugin updates.

Ramp-Up

  • Team Onboarding:
    • Developers: 1–2 days to understand spatie/laravel-translatable + Filament plugin hooks.
    • Designers: Minimal impact; plugin uses Filament’s existing UI components.
    • Content Editors: Training needed for locale switching and translation workflows.
  • Training Materials:
    • Record a demo of CRUD operations with translatable fields.
    • Document common pitfalls (e.g., unsaved translations, locale conflicts).
  • Pilot Phase:
    • Roll out to a non-critical Filament resource first (e.g., "About Us" pages).
    • Gather feedback on UX (
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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit