F
Filamentβ€’3mo ago
Excavator

Spatie translatable

I'm using https://github.com/filamentphp/spatie-laravel-translatable-plugin to translate some fields in my models - is there a suggested way to actually render those on the frontend? Should this be done by the plugin, or do I just process data before passing to props/just render in React depending on the locale? I see a bunch of different "translatable" plugins mentioned, so I'm not sure if I'm using the "wrong" one? If there's such thing as wrong even πŸ˜„
GitHub
GitHub - filamentphp/spatie-laravel-translatable-plugin: [READ ONLY...
[READ ONLY] Subtree split of the Filament spatie/laravel-translatable Plugin (see filamentphp/filament) - filamentphp/spatie-laravel-translatable-plugin
Solution:
as Dennis mentioned the plugin handle the filament part only. the frontend is out of control haha your best way to create accessors to get the translated attributes depend on your app, $this-title will return array, so you also can create a method and pass the $lang btw not sure if you're on v4 or v3, since this is for v4...
GitHub
GitHub - lara-zeus/spatie-translatable
Contribute to lara-zeus/spatie-translatable development by creating an account on GitHub.
Jump to solution
8 Replies
Dennis Koch
Dennis Kochβ€’3mo ago
It's now maintained by LaraZeus: https://github.com/lara-zeus/translatable
GitHub
GitHub - lara-zeus/translatable: A Fork of the Filament spatie/lara...
A Fork of the Filament spatie/laravel-translatable Plugin - lara-zeus/translatable
Excavator
ExcavatorOPβ€’3mo ago
Maybe @Lara Zeus could give some insight - or should I move this into a separate topic, since it's not your plugin anymore?
Dennis Koch
Dennis Kochβ€’3mo ago
What are you struggling with? The plugin is there to handle the gap between Filament and the underlying Spatie package.
Excavator
ExcavatorOPβ€’3mo ago
I was just wondering if the plugin should/does handle what model fields are returned, but when I think of it - there's no interraction of the plugin with anything else then filament at all. I was just wondering what would be a typical approach to handle fetching the correct translation based on a locale - mapping in the controller, maybe adding a getter to each model or making a helper to do that in react?
Dennis Koch
Dennis Kochβ€’3mo ago
The Spatie plugin does the fetching and saving of the translations. The Filament plugin acts as a bridge between both. You need to configure your translatable according to the Spatie docs
Solution
Lara Zeus
Lara Zeusβ€’3mo ago
as Dennis mentioned the plugin handle the filament part only. the frontend is out of control haha your best way to create accessors to get the translated attributes depend on your app, $this-title will return array, so you also can create a method and pass the $lang btw not sure if you're on v4 or v3, since this is for v4
GitHub
GitHub - lara-zeus/spatie-translatable
Contribute to lara-zeus/spatie-translatable development by creating an account on GitHub.
Lara Zeus
Lara Zeusβ€’3mo ago
also check spatie docs, they already have a lot of methods that I am sure its will be helpful
Excavator
ExcavatorOPβ€’3mo ago
Welp, I'm not sure how I didn't find these docs πŸ˜„ Thanks for the help!

Did you find this page helpful?