views:

66

answers:

1

I am working on upgrading our site to work in different languages.

My plan is to store paragraphs of text in mulitple languages and give each paragraph an identifier.

Example
id => '1'
brief => 'welcome_paragraph'
en => 'Welcome to our website!'
de => 'Willkommen auf unserer Website!'

Requirements

  • quickly retreived
  • edited via CMS at any time
  • easy to add new languages

So is the best solution to store this in a database table? And if so, which of the following is the best table setup:

One table, a column for each language and row for each brief:

ID, brief, en, de, es

Or two tables, one with breifs, one with translations:

ID, brief

ID, language, translation

In each page, I intend to do....

echo $page->translate($language, $brief);

Multiple times to bring out the require piece of text.... will this be slow to keep calling a database with:

SELECT translation FROM translations 
WHERE language = 'es' AND brief = 'welcome_paragraph'
LIMIT 1

Multiple times on each page? Is there therefore a better way to store this as flatfile? Or a PHP file which is generated on update containing a large array of translations?

$english = array(
'message1' => 'message1',
'message2' => 'message2',
'message3' => 'message3');


$german = array(
'message1' => 'Nachricht1',
'message2' => 'Nachricht2',
'message3' => 'Nachricht3');

Much like the example on the Zend Translate page I'm not considdering using Zend Translate at this time... I assume there is a cost to it?

+2  A: 

http://php.net/manual/en/book.gettext.php is the solution for the multi-language site

you can take a look at wordpress to watch gettext in action.

Col. Shrapnel
I agree this is the best solution. If you go the database way you will need to implement some caching otherwise it is a huge waste of resources.
Ivo Sabev