thesimons's avatar

Best approach to multi language sites

Hello,

is there any thing built-in to use with Laravel 12 to handle multi-language sites?

I have no problem writing all the logic from the scratch but if anything has been already created I wouldn't complain giving it a try.

Thanks Simon

0 likes
3 replies
RemiM's avatar

You can have a look at Laravel Lang, which is nice and easy to setup and work with, and eventually check at the official Laravel documentation about localization.

iamgeorge's avatar

This is my multilingual blog with categories and tags

php artisan make:model Post -m
php artisan make:model Category -m
php artisan make:model Tag -m
php artisan make:model Language -m
php artisan make:model PostTranslation -m
php artisan make:model CategoryTranslation -m
php artisan make:model TagTranslation -m

posts table:

Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('picture')->nullable();
    $table->date('date');
    $table->timestamps();
});

categories table:

Schema::create('categories', function (Blueprint $table) {
    $table->id();
    $table->timestamps();
});

tags table:

Schema::create('tags', function (Blueprint $table) {
    $table->id();
    $table->timestamps();
});

languages table:

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

post_translations table:

Schema::create('post_translations', function (Blueprint $table) {
    $table->id();
    $table->foreignId('post_id')->constrained()->onDelete('cascade');
    $table->foreignId('language_id')->constrained()->onDelete('cascade');
    $table->string('title');
    $table->text('short_text');
    $table->text('long_text');
    $table->timestamps();
});

category_translations table:

Schema::create('category_translations', function (Blueprint $table) {
    $table->id();
    $table->foreignId('category_id')->constrained()->onDelete('cascade');
    $table->foreignId('language_id')->constrained()->onDelete('cascade');
    $table->string('name');
    $table->timestamps();
});

tag_translations table:

Schema::create('tag_translations', function (Blueprint $table) {
    $table->id();
    $table->foreignId('tag_id')->constrained()->onDelete('cascade');
    $table->foreignId('language_id')->constrained()->onDelete('cascade');
    $table->string('name');
    $table->timestamps();
});

if you like this approach i can send full code, categories and tags are like filter...

Please or to participate in this conversation.