0

Possible Duplicate:
How would you transform a pre-existing web app in a multilingual one?
Best way to internationalize simple PHP website

I'm trying to figure out how to translate all the static texts on my webpage (I'm using PHP). But I'm not really sure what the "correct" way is. This is what I thought of so far, but maybe it's all wrong :D

1. For every static piece of text on the page, just get the translation with something like "getTranslation("Hello World!") and it will just look up the translation in the database or a file like XML/CSV/PHP with all the translations.

But this seem pretty bad since we will have to query the database or parse the file on every page, everytime it's refreshed/loaded.

2 Everytime a page is loaded I could read from the database/file and store the translations for the current language in an array and get the translations from the array as the page is building, instead querying the database / parsing the file again.

3 Is there some way to read the translations only once and then make it accesible for all pages? The only thing I can think of is php's SESSION but it just seems so wrong to store the translations there.

So what the "most common" or "right" way to do it?

Happy hunting!

Community
  • 1
  • 1
TTT
  • 23
  • 4

1 Answers1

2

Sounds like you need gettext. gettext is widely used and widely supported. I'm pretty sure it's also pretty well optimized.

Kris
  • 40,604
  • 9
  • 72
  • 101
  • I would like to use that but the little evil men at my web hosting company won't allow it. – TTT Jun 06 '12 at 19:36
  • That sounds like you need a less evil little man? Or follow this question: http://stackoverflow.com/questions/2275270/whats-the-simplest-php-alternative-to-the-php-gettext-extension-which-can-be-su – Kris Jun 06 '12 at 20:02