Reputation: 21
I'm an entry-level developer working on an e-commerce project using Laravel 10 and Vue.js 3. I've already set up i18n for translations in Vue.js, but now I'm struggling with structuring my database to support multilingual product data.
The website admin should be able to add products in two languages. I'm wondering if there's a recommended approach, library, or best practice to make this process simpler.
Should I store translations in separate tables, use JSON columns, or is there a package that helps with this? Any guidance would be greatly appreciated!
Thanks in advance!
So far, I’ve considered two possible approaches:
Using a JSON column in the database to store translations for product names, descriptions, etc. This seems simple but might make querying and filtering data more complicated. Creating a separate translations table with columns like product_id, language, name, and description. This approach seems more structured but adds complexity to queries and relationships. I expected to find a Laravel package that simplifies multilingual database handling, but I haven't found one that fits my case well. I'm looking for guidance on the best approach to balance performance, maintainability, and ease of use.
Upvotes: 2
Views: 21
Reputation: 21
I recommend using this package: https://github.com/spatie/laravel-translatable?spm=5aebb161.2ef5001f.0.0.5fb8c921cBCCGc. I think it is the best one that fits your problem.
If you prefer not to use the package or if you want more control, I would create a separate table for translations. This is particularly useful if your application has a lot of dynamic content and you need to handle translations in a more structured way. For static content or less frequent changes, translating it on the frontend could also be a viable option.
For example, I worked on a project where I had to manage data translations, and due to technical needs and limited traffic, I chose to create a separate table. This approach worked well because it allowed me to easily scale the translations and ensure the data was structured properly.
Upvotes: 1