Current location: Hot Scripts Forums » Programming Languages » PHP » Multiple language support in PHP - best method?

Multiple language support in PHP - best method?

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Jul 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Question Multiple language support in PHP - best method?

I'm writing a web application from the ground up which needs to support multiple world languages.

My first instinct was to create a language file for each language, which contains all the textual output of the software in each language, defined as constants or variables.

but then I ran into a problem of how do I load it in without massive waste of resources?

If I load it in as a mass of session variables at user login, then there's a copy in RAM for each session. If I load it in as a bunch of regular variables or constants every time a user requests a new page, well, there's a ton of RAM and redundant loading too! Even worse!

Is there some place I can define the language strings as superglobal variables that are loaded into one place in RAM on system boot / PHP startup? Or is there an even better way? I was looking at the superglobal types, and I'm not sure any of them were really built for that purpose.

Thanks,

--Harlock
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

Looks like your site will have million pages Don't worry, just store messages in one include file like

<?
$m = array(
'en' => array('welcome'=>'Welcome!'),
'es' => array('welcome'=>'Hola!'));
...
?>

and require it on every request, then just use <?=$m[$_SESSION['lang']]['welcome']?> in the pages to display localized messages.

You could also make multiple message files like en.msg or es.msg and require them based on the value of the sesison variable.

You easily cannot preload messages on the PHP startup so they stay in memory and are available for subsequent requests.
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #3 (permalink)  
Old
Newbie Coder
 
Join Date: Jul 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
You easily cannot preload messages on the PHP startup so they stay in memory and are available for subsequent requests.
No wonder why all those CMS systems are so slow...all that redundant loading... (and massive feature creep...which is what got me writing my own stuff in the first place...)
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
bilingual language in php EvilDeveloper PHP 3 05-05-05 09:22 AM
help with multiple select used with php and mysql isaacmlee PHP 2 10-15-04 01:34 PM
javascript multiple select menu for php? isaacmlee JavaScript 1 10-15-04 09:53 AM
Triangle Solutions Ltd presents PHP Multiple Newsletters usmwf PHP 0 03-26-04 09:29 AM


All times are GMT -5. The time now is 07:50 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.