Jump to content

Cache PHP pages


StormTheGates

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
}
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.