Welcome Guest, Not a member yet? Register   Sign In
Model for a multilingual site
#1

Hello! Just started using CodeIgniter 4 and started developing a multilingual site. For database structure, I decided to go with a table that keeps the shared information and a secondary table that keeps the translations.
For example, a news page - table news with fields: id, published_by, created_at, updated_at, deleted_at and the secondary table news_translation with fields: news_id, language_code, title, article. I have a composite key of news_id and language_code and a foreign key on news_id to news.id.
Now the thing that I can't think of how to do best is how should I structure the model/models? Should I use separate models and entities for the news table and news_translation table and if I do, how would I join the news_translation when showing a list of news if every model/entity represents one table? Also, how would you go with the model of the news_translation table which have a composite key instead of a primary key on one column?
The second way that comes to mind is a manual creation of a single news model that handles both tables.
Which would be the best way to go?
Thank you for your time!
Reply
#2

I developed a simple multilingual blog with CI4. The way I got around the "translation problem" is that every article is really a stand alone article in english or in french. They're not a translation. So it's a lot simpler. There's no link between the articles in different languages and there's no problem if an article exists only in one language and not the others. It may be a problem if you want to switch language while you're reading something. But in my case, it's not really a problem.

I wrote a blog post on how to make a bilingual CI4 web app using this logic if you're interested.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(07-12-2022, 01:46 PM)includebeer Wrote: I developed a simple multilingual blog with CI4. The way I got around the "translation problem" is that every article is really a stand alone article in english or in french. They're not a translation. So it's a lot simpler. There's no link between the articles in different languages and there's no problem if an article exists only in one language and not the others. It may be a problem if you want to switch language while you're reading something. But in my case, it's not really a problem.

I wrote a blog post on how to make a bilingual CI4 web app using this logic if you're interested.

That would be a problem in my case as they need to be on the same link and sharing some common attributes Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB