I’ve developed a website more than a year ago. The content were/is in two languages and now I need to build a database driven update/data insertion system for them to inserte some news, events etc.
Is the best approach to create tables like this:
news_id int(10) unsigned PK
lang_id int(2)
status tinyint(1)
title varchar(255)
title_en varchar(255)
title_es varchar(255)
content text
content_en text
content_es text
date_inserted datetime
date_modified datetime
type varchar(45)
atach text
then create a table for the languages
You should only care about one language for any one particular request. While you could only select the language that the page request requires, it still isn’t best practice to organise your content in such a way.
What you should do is use locales and provide defaults for a content. Because while you might think you will always create two versions of a piece of content, in a less than perfect world this doesn’t always happen.
So, you would first create your model to reflect this relationship. For simplicity I will just refer to this as
content. But you could of course have your content to be anything.Now, you just need a way to know which locale the user wishes to use. I prefer using Zend_Locale for managing all of my locales, and Zend_Translate for short key=>value translations. (This isn’t suitable for long content translations though).
When you know which locale you want to use, all you need to do is perform your query to select with a join.
The Beauty
The beauty of all of this however, is that if you haven’t created your content for a particular language version, then you can still default and roll onto your base language which the original article/content was written in.