Skip to main content

On This Page

Implementing Multilingual Runtime Collections in Filament Studio v1.2.0

3 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Building multilingual runtime collections in a Filament plugin

Developer Serhii has released Filament Studio v1.2.0 to provide runtime data modeling capabilities for Filament v5 admin panels. This update introduces a multilingual system where translation behavior is defined per-field rather than per-record, allowing developers to mix localized and shared data within a single collection.

Why This Matters

Standard localization models often rely on static schema changes or JSON columns that force an all-or-nothing approach to translations. In runtime-defined environments like Filament Studio, this creates technical debt because facts such as prices, dates, or boolean flags should remain shared across all locales while only specific content fields like titles require translation. By implementing a granular EAV storage model with a locale-specific uniqueness boundary, the system avoids data noise and ensures that API-driven applications can scale without requiring new migrations for every localized attribute.

Key Insights

  • Field-Level Granularity: Individual fields within a collection are marked as translatable or shared, preventing unnecessary translation overhead for non-content data like prices or dates.
  • EAV Storage Strategy: The studio_values table implements a composite key consisting of record_id, field_id, and locale to store localized data without schema modifications.
  • Locale Resolution Order: The LocaleResolver service determines the active locale by checking query parameters, then the X-Locale header, session data, and finally collection or global defaults.
  • API Fallback Metadata: The getRecordDataWithMeta() method provides explicit feedback to API consumers by listing which fields fell back to the default locale.
  • Snapshot Consistency: Versioning tools in Filament Studio store all localized values in snapshots, ensuring that restoring a previous version restores the entire multilingual state rather than just the active locale.

Working Examples

Global configuration for enabling multilingual support and defining available locales.

config/filament-studio.php
'locales' => [
    'enabled' => true,
    'available' => ['en', 'fr', 'de'],
    'default' => 'en',
],

Retrieving localized data for a specific locale or fetching all translation maps simultaneously.

$data = EavQueryBuilder::for($collection)
    ->locale('fr')
    ->getRecordData($record);

$allData = EavQueryBuilder::for($collection)
    ->getAllLocaleData($record);

Requesting localized content via the REST API using the X-Locale header.

curl -H "X-Api-Key: your-key" \
     -H "X-Locale: fr" \
     "https://your-app.com/api/studio/posts"

Practical Applications

  • Dynamic E-commerce: Use Filament Studio to manage product catalogs where titles are localized for French and English markets, while inventory counts and prices remain shared globally. Pitfall: Failing to use shared fields for prices can lead to inconsistent pricing across different language versions of the same product.
  • Headless CMS APIs: Expose runtime-defined collections via REST with OpenAPI documentation that includes locale metadata for frontend consumers. Pitfall: Relying on silent fallbacks without metadata makes it impossible for client-side applications to detect and flag missing translations for editors.

References:

Continue reading

Next article

BitLease Launches Payment-Based Ownership Platform for Digital Assets

Related Content