Anyone? :)
Building a Multilingual Website with Laravel
Hi,
I want to create a very simple multilingual website. I decided to use dimsav/laravel-translatable because it is currently the most popular package for building a multilingual website with Laravel. If you think you have a better solution/package, please tell me. Anyway, my website will only have articles with title & body, but in two different languages: English (default) and German.
So, I installed dimsav/laravel-translatable, and now there are two tables:
articles:
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
article_translations:
Schema::create('article_translations', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('article_id');
$table->string('locale')->index();
$table->string('title');
$table->text('body');
$table->unique(['article_id','locale']);
$table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');
});
Also, based on documentation, I have these two models:
Article.php:
class Article extends Model
{
use Translatable;
public $translatedAttributes = ['title', 'body'];
protected $fillable = ['title', 'body'];
}
and ArticleTranslation.php:
class ArticleTranslation extends Model
{
public $timestamps = false;
protected $fillable = ['title', 'body'];
}
But now, I'm not sure how to do the rest.
1. QUESTION: How would you do creating of articles? How would your blade form look like?
- Would your form had one select (dropdown) from which the user (author) will be able to select the language of article?
- Or that form will have different elements (inputs) for every possible language (for example, two title input elements, two body input elements... one for English version and one for German)?
- Or maybe you would just check what is the current application locale, and according to that your application will know in which language that article should be? If that's the way you would do this - can you give me some instructions (starting points) how to do it, how would your routes look like, where and how would you check current locale, how would you add version of that article in the other language... ?
- Or you would do it in some other way?
Please or to participate in this conversation.