F
Filament7mo ago
core

Pros and Cons for Translations DB schema: json vs dedicated tables

I need to decide on my DB schema, I have a DB with multiple pivots and a lot of eager loading using with(), I know json can complicate the queries and add performance overhead. How significant is it? Looking into spatie/laravel-translatable and astrotomic/laravel-translatable. And is there a a package for the latter?
12 Replies
Andrew Wallo
Andrew Wallo7mo ago
Maybe I never understood why translations should be stored in the database, but I thought I would share this package: https://github.com/andrewdwallo/transmatic You can look at the code in my project here and see how the package was used: https://github.com/andrewdwallo/erpsaas
GitHub
GitHub - andrewdwallo/transmatic: Automate and streamline real-time...
Automate and streamline real-time text translations in your Laravel applications - GitHub - andrewdwallo/transmatic: Automate and streamline real-time text translations in your Laravel applications
GitHub
GitHub - andrewdwallo/erpsaas
Contribute to andrewdwallo/erpsaas development by creating an account on GitHub.
core
core7mo ago
so how is this persisted?
Andrew Wallo
Andrew Wallo7mo ago
What do you mean? Translations can be dynamically set based on application locale. Translations are applied to field labels, etc. You can look at my repo source code for erpsaas to see Or you can try it out if you want
core
core7mo ago
Let’s say i have a recipe app and need to translate the step by step instructions In the steps table
Andrew Wallo
Andrew Wallo7mo ago
Why would you need to store translations in the database to do that?
Lara Zeus
Lara Zeus7mo ago
I am assuming you're talking about model translation not the phrases in (lang dir)... both spatie/laravel-translatable and astrotomic/laravel-translatable stores the translation in json I have an app build entirely with separate table for all text, like (post title, post desc ...) and by default filament don't support this, so you will have more DIY stuff to do and still some areas like relation managers and the repeaters I couldn't find a solution for it eventually it depend on the size of these records and how much you need them... like titles you need it every where, so I would go with json but if it's on specific tables and you have many maybe more than two lang, use dedicated tables
core
core7mo ago
I am asking how is it stored ? as a json file on AWS translate?
Andrew Wallo
Andrew Wallo7mo ago
Yes there are stored in json You would just have a json translation file that have the step by step instructions in each language.
core
core7mo ago
cool, i'll play around with it today thanks
Andrew Wallo
Andrew Wallo7mo ago
Here is an example.
core
core7mo ago
hi I am getting an error:Wallo\Transmatic\Transmatic::translate(): Argument #2 ($replace) must be of type array, string given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 353 for :$translatedText = Transmatic::translate('Hello World', 'es'); // Hola Mundo, and if I return it as an array it just returns the en besides what is the flow to manage the translated text with the model object id ?
Andrew Wallo
Andrew Wallo7mo ago
That’s because the second argument is replace. The 3rd argument is the language. Maybe I should clear that up in the docs.