3

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

My plan is to store paragraphs of text in multiple 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 retrieved
  • 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 considering using Zend Translate at this time... I assume there is a cost to it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jon M
  • 454
  • 1
  • 7
  • 20
  • Why ‘generated on the fly’? You're not expecting translations to change at run-time, are you? Why not just in a normal static PHP include? – bobince Apr 07 '10 at 13:56
  • "I'm not considdering using Zend Translate at this time... I assume there is a cost to it?" If you mean cost as in dollars, no, there's no cost. Zend framework is free and open source, under the BSD license. That's about as free as it gets. – Frank Farmer Apr 07 '10 at 14:10
  • I've changed "on the fly", should be on update, thanks for pointing that out bobince. – Jon M Apr 07 '10 at 14:12
  • possible duplicate of http://stackoverflow.com/questions/2344383/what-is-the-best-way-to-put-a-translation-system-in-php-website and a couple of others that cover similar grounds. – Gordon Apr 07 '10 at 14:21

1 Answers1

3

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.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 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 Apr 07 '10 at 14:03