Answer the question
In order to leave comments, you need to log in
How to organize the database structure for multilingual CMS?
Good day, toasters!
The question is actually this.
How is it most convenient to organize the database structure for writing a multilingual CMS?
The goal is this: You need to somehow store translations of section names, translations of news, pages, and then you can organize a search on the site, and specifically on translations of a particular language.
I organized it like this (table structure with translations of news and sections in this case):
----------------------------------------------------------------
| id | section_id | news_id | lang | title | description | ... |
----------------------------------------------------------------
$news = News::get();
foreach ($news as $nws) {
$data[] = [
'id' => $nws->id,
'good' => $nws->good,
'translates' => $nws->translations()->where('lang', App::getLocale())->get()->toArray()
];
}
Answer the question
In order to leave comments, you need to log in
For each entity, two tables are created: the main table and the table with translations. There should also be a table with a list of languages (languages) For example, we have a Post entity (publication), it will have the following database structure:
id, slug, published_at
id, post_id, language_id, title, content
I made it a rectangle: one entry is one publication / article, and translations are in columns.
id | section_id | news_id | title[en-en] | title[ru-ru] | description[en-en] | description[ru-ru] |...
it's just that you will have more than 4-5 languages - this is unlikely, but the speed of searching (filtering) in the desired language and in the required columns - this greatly affects the better. Don't forget to clearly indicate the columns that you want to display in the query results (and sometimes LIMIT too) and that's it.
In fact, it turns out that one piece of news is a set of records in the database. If you resort to the 1st normal form, then you get something like
And the primary key in this case is already a bunch of id + lang_id. With an incoming request, the language that the browser needs is already determined and is simply substituted for all values.
But then you will have to organize work with AUTO_INCREMENT yourself, since uniqueness already goes at the id + lang_id level
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question