BuddhistPunk
Gawd
- Joined
- Mar 21, 2002
- Messages
- 656
Hello all,
I am currently in the throws of putting together a site that is required to support multiple languages. Current requirements are English and Spanish however the design need to be flexible enough to add others in the future.
At face value this seemed easy enough, so I embarked on this task by using the following design:
Basically the default language is English, however every page has a series of flags on them, when the use clicks on the flag the language key (en for English, es for Spanish) is passed back to PHP SELF on a querystring, something like this:
mypage.php?displayLanguage=en
In the PHP code this value is picked up and validated, and then set into a session var. Based on the value of this session var the PHP code will then include a file that contains language definitions for the entire site, for example
Within these files language files I have a series of defines for each chunk of text, for example:
LanguageData.en.php
LanguageData.es.php
As mentioned above these file include defines for all text used on all pages within the site (upwards of 200 defines)
Within my page code I can then do the following to create outputs
Now this all works, however as the site is expanding these language definition files are growing at an alarming rate. This is where I think there may be a issue with the design idea of using defines in a single php script. Also there is something in the back of my head that says loading all text for a specific language for the entire site on every page refresh is bordering on crazy.
As I understand the internal mechanisms of PHP, when a define is loaded this is a one time affair, i.e. for every page refresh and view the definitions are essentially reloaded. If this is the case then my code is loading/parsing/storing a full site definition file on every page view and this is going to turn into a massive and unnecessary overhead (a single page might only need 10 of the 100+ defines in the file).
If my assumption is incorrect and internally the php engine keeps a cache of defines created on other pages, then this isnt as big a problem as I think it might be. However if my assumption is correct that an alternative has to be found.
The most logical course of action would seem to be creating a unique language unique definition file for each page, however this then makes language administration considerably more difficult. As an example the site currently has 19 pages, that would be 38 language files to maintain!
So with all this in mind, does anybody have any suggestions on the best way forward for this?
I am currently in the throws of putting together a site that is required to support multiple languages. Current requirements are English and Spanish however the design need to be flexible enough to add others in the future.
At face value this seemed easy enough, so I embarked on this task by using the following design:
Basically the default language is English, however every page has a series of flags on them, when the use clicks on the flag the language key (en for English, es for Spanish) is passed back to PHP SELF on a querystring, something like this:
mypage.php?displayLanguage=en
In the PHP code this value is picked up and validated, and then set into a session var. Based on the value of this session var the PHP code will then include a file that contains language definitions for the entire site, for example
PHP:
if ($_SESSION["displayLanguage"] == "es")
{
include ("LanguageData.es.php");
}
else
{
include ("LanguageData.en.php");
}
Within these files language files I have a series of defines for each chunk of text, for example:
LanguageData.en.php
PHP:
define("LANG_INDEX_NUMBERS", "one two three")
define("LANG_INDEX_FOO", "foo")
define("LANG_INDEX_BAR", "bar")
...
...
...
LanguageData.es.php
PHP:
define("LANG_INDEX_NUMBERS", "uno dos tres")
define("LANG_INDEX_FOO", "el foo")
define("LANG_INDEX_BAR", "la bar")
...
...
...
As mentioned above these file include defines for all text used on all pages within the site (upwards of 200 defines)
Within my page code I can then do the following to create outputs
PHP:
echo '<div class="numbers">'.LANG_INDEX_NUMBERS.'</div>';
echo '<div class="foobar">'.LANG_INDEX_FOO.LANG_INDEX_BAR'</div>';
Now this all works, however as the site is expanding these language definition files are growing at an alarming rate. This is where I think there may be a issue with the design idea of using defines in a single php script. Also there is something in the back of my head that says loading all text for a specific language for the entire site on every page refresh is bordering on crazy.
As I understand the internal mechanisms of PHP, when a define is loaded this is a one time affair, i.e. for every page refresh and view the definitions are essentially reloaded. If this is the case then my code is loading/parsing/storing a full site definition file on every page view and this is going to turn into a massive and unnecessary overhead (a single page might only need 10 of the 100+ defines in the file).
If my assumption is incorrect and internally the php engine keeps a cache of defines created on other pages, then this isnt as big a problem as I think it might be. However if my assumption is correct that an alternative has to be found.
The most logical course of action would seem to be creating a unique language unique definition file for each page, however this then makes language administration considerably more difficult. As an example the site currently has 19 pages, that would be 38 language files to maintain!
So with all this in mind, does anybody have any suggestions on the best way forward for this?