Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ufo973's avatar

multilingual database

I hope this thread finds everyone healthy.

I am designing a multilingual database using laravel eloquent.

Here is my tables and codes:

Schema::create('locales', function(Blueprint $table) { $table->increments('id'); $table->string('code', 2); $table->string('name'); });

Schema::create('products', function(Blueprint $table)
{
    $table->increments('id');
    $table->string('thumbnail');
    $table->string('images');
    $table->timestamps();
});

Schema::create('product_translations', function(Blueprint $table)
{
    $table->increments('id');

    $table->string('name');
    $table->string('content');

    $table->integer('product_id')->unsigned();
    $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');

    $table->integer('locale_id')->unsigned();
    $table->foreign('locale_id')->references('id')->on('locales')->onDelete('cascade');

    $table->unique(['product_id', 'locale_id']);

});

And it is working fine. But now i have to create another table for product categories. There are 3 categories for each product. but each category will be translated. and since i don't have much experience with multilingual db designs, i don't know what is the proper way to do it.

Can somebody post a code how the new category table should look?

Here is my product_categories table so far:

Schema::create('product_categories', function(Blueprint $table) { $table->increments('id'); $table->string('locale_id'); $table->string('category'); }); Thanks in advance!!

0 likes
2 replies
ufo973's avatar

Wow....no one offered a single tip :/

Rjs37's avatar

Would you really need locale_id on your product_categories table? Is it always going to be three categories per table? Making use of a many to many relationship would probably be useful in your situation. You could have a products table, a categories tables and a product_categories (id, product_id, category_id) table which would link the other two tables.

Then alongside that you could have your product_translations and category_translations tables to store the text you want to translate.

I don't know if there is a 'proper' way to do multi-lingual databases. I have seen the translation tables suggested before though it feels wasteful to me to create so many extra tables. I think I'd be more tempted to use a single table to store all translations but I've not put a lot of thought into it yet and what the implications of it would be.

Please or to participate in this conversation.