how are you guys? I’m trying to make my PHP script accept many languages, and give the admin the option of change the Phrases in the script.
So, I found that many people store the Phrases in the database, but my question is do I need to SELECT all the phrases from my database each time I opened a page ? or what I have to do?
Phrase EN FR
-----------------------------------------------------------------------
err_no_page There was an error. il y avait une erreur.
in each page I need to use maybe phrases, what is the perfect method to get them from the database without exhausting the server.
Thank’s in advance.
You should normalize your database like this:
PHRASES
TRANSLATIONS
Then you can just select all the translations for a single language directly:
The benefit of doing it this way is that you can easily add more languages without changing the structure of your database.
If these phrases are used frequently (as they probably are in a web app) then you should consider reading them in once into some kind of in-memory dictionary cache when your application starts up, rather than retrieving them from the database for each page load.
EDIT
Check out the PHP module memcache for a possible way to implement your cache.