StormTheGates Posted July 20, 2008 Share Posted July 20, 2008 Here is my situation: I run a game that I am trying to make multi lingual. There is a language file for every regular file. On the language files there are arrays of all the strings for each language. For example users.lang.php contains 6 arrays of 8 strings each, an array for each language and then all the strings in that language. Now some of these pages are quite large, and have a lot of text 100-300 strings. Is there a way to cache these php pages so that the server dosnt have to go through all the arrays each time? The language files will not be changing so I was hoping I could find a way to cache them to make it faster to access. Any ideas? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 Why not user a translator function that converts english-> Other languages such as googles and just use cURL to view it Quote Link to comment Share on other sites More sharing options...
jonsjava Posted July 20, 2008 Share Posted July 20, 2008 not sure this will help, but I do this with my scripts: in my config.inc.php (the configuration file. yours may be named something else, of course) <?php $language = "en_US"; //can be en_GB, l_SP, IT, etc. then in all my files, I have this: <?php include("config.inc.php"); include($language."/lang_db.inc.php"); and the lang_db.inc.php holds all the strings that I'll need translated. Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted July 20, 2008 Author Share Posted July 20, 2008 Why not user a translator function that converts english-> Other languages such as googles and just use cURL to view it Can you explain a bit more? I am not very knowledgeable about cURL. Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted July 20, 2008 Author Share Posted July 20, 2008 not sure this will help, but I do this with my scripts: in my config.inc.php (the configuration file. yours may be named something else, of course) <?php $language = "en_US"; //can be en_GB, l_SP, IT, etc. then in all my files, I have this: <?php include("config.inc.php"); include($language."/lang_db.inc.php"); and the lang_db.inc.php holds all the strings that I'll need translated. The language files in one page would be far to large to load on every page. I only need a select chunk at any given moment. Most of my pages look like this: <?php include 'languages/main.php'; $lang = GetLang(); echo "Statement: $lang[0]"; ?> And on main.php <?php function GetLang(){ $fr = array( 0 => "seulement rapporter les bogues dans le jeu pour eux.", 1 => "les modérateurs pour signaler des problèmes et des bugs à eux.", 2 => "pour aider les bureaux. S’il vous plaît demander jeu des questions qui leur sont confiées. ", 3 => "pour les personnes qui possèdent des casinos. ", 4 => "patrons pour la famille.", 5 => "la main droite pour les hommes.", 6 => "pour vos amis en ligne. ", ); $de = array( 0 => "bericht nur bugs im spiel zu ihnen. ", 1 => "moderatoren für probleme und bugs zu ihnen", 2 => "für Help Desks. Bitte fragen sie spiel fragen zu ihnen. ", 3 => "für Menschen, die eigenen Casinos. ", 4 => "für Familie Bosse. ", 5 => "rechte hand für männer.", 6 => "für ihre online-freunde. ", ); ... if($_SESSION['lang'] == 'en'){ return $en; } elseif($_SESSION['lang'] == 'fr'){ return $fr; } elseif($_SESSION['lang'] == 'de'){ return $de; } elseif($_SESSION['lang'] == 'it'){ return $it; } elseif($_SESSION['lang'] == 'sp'){ return $sp; } elseif($_SESSION['lang'] == 'nl'){ return $nl; } else { return $en; } } ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted July 20, 2008 Share Posted July 20, 2008 I was talking about having a folder for each language. something like this: languages en_US lang.inc.php l_SP lang.inc.php en_GB lang.inc.php and have your script call the language file that it needs, either by hard-coding it, which I'm guessing you aren't wanting to do, or with session data. then include that file. for session stuff: include("languages/".$_SESSION['lang']."/lang.inc.php"); so, if their language is en_US, it will include languages/en_US/lang.inc.php rather than loading every possible language. Quote Link to comment Share on other sites More sharing options...
unkwntech Posted July 20, 2008 Share Posted July 20, 2008 I don't believe theres a way to cache it however for the sake of sanity if you only have 1 file per language I would do something like this <?php $lang = getLang(); require('languages/ . $lang . ".inc.php"); This would give one folder 'languages' with each language in its own file, which would clean up the folder contains the languages folders. But thats just my opinion. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 http://translate.google.com/translate?u=http%3A%2F%2Fwww.phpfreaks.com%2Fforums%2Findex.php%2Ftopic%2C207704.0.html&hl=en&ie=UTF8&sl=en&tl=da Now if u use cURL you can simply display that page less the google frame and be done. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.