Home > PHP > PHP and Internationalization support

PHP and Internationalization support

For the last almost three months I have been doing some PHP programming and its been fun using it šŸ™‚

The project I have been working on is almost complete from the features side that we needed to support but now the issue which just came in was having language support and Internationalization the whole GUI. That actually means having a “Select Language” option on the login screen and then customizing the whole GUI according to that. I have done similar kind of support before in C but at that time I was using a very nice GkyeFile parser from Glibc which had proper support for locale, but being new at PHP I had no idea where to start with and as I started looking for a solution, it ended up being a very simple one. Here is what can be done if someone wants to do the same thing simply in PHP….

– Have a global array called $language and then assign all your GUI labels and error messages like this:

$language[‘btnlbl’] = ‘Button’;
$language[‘Err001’] = ‘Error executing function’;

And put this array in a PHP file (where each language like english, french, german etc etc have a specific {langname}.php file)

– Now we need to use the above mentioned language PHP files…

We kept English as the master language so thats the default, this is how it can be handled:

//If no language is set use English
if (!isset($configuration[‘defaultlanguage’])) $configuration[‘default_language’] = ‘english’;

//Setting up the array and setting all values from the PHP file
$language = array();
require_once(‘./language/english.php’);

And if user has select a specific language on the login screen use the following:

if (isset($_language)) {
include(“./language/{$_language}.php”);
$_SESSION[‘weblang’] = $_language;
}

Now all I had to do was use english.php through out the code and then send the other {language}.php to the translators… and we ended up having a proper internationalization support.

Shoaib Mir
shoaibmir[@]gmail.com

Advertisements
Categories: PHP Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: