PHP Tutorial: Developing a Login – Part 1 - Localization




Localization

You might have noticed some of the following constants within the previous methods:

COMPLETE_EMAIL
INVALID_EMAIL
COMPLETE_PASSWORD
INVALID_USER_PASS

Instead of simply embedding our error messages/notifications within our scripts/pages, we define them in some file that functions as our language file – which means the Zulu guy next door can simply edit that file and thereby transform the output into his own language.

The language file will look something like this:

 
$constants = array(); 
$constants['INVALID_USER_PASS'] = 'Ongeldige gebruiker naam of wagwoord';
$constants['COMPLETE_EMAIL'] = 'Voltooi asseblief die epos veld';
$constants['INVALID_EMAIL'] = 'Ongeldige epos adres';
$constants['COMPLETE_PASSWORD'] = 'Voltooi asseblief die wagwoord veld';
$constants['EMAIL_CAPTION'] = 'Epos adres';
$constants['PASSWORD_CAPTION'] = 'Wagwoord';
$constants['LOGIN_CAPTION'] = 'Teken in';
$constants['LOGOUT_CAPTION'] = 'Teken uit';
$constants['LOGIN_TEXT'] = 'Ingeteken as:';
$constants['LOGOUT_TEXT'] = 'U het suksesvol uit geteken';
$constants['HOME_CAPTION'] = 'Tuis';
require("parse.php");
 

Notice the code block within the parse.php file:

 
foreach($constants as $key=>$value) {
	if (isset($_GET['js'])) {
		echo 'var '.$key.' = "'.$value.'";'."\n";
	}
	else {
		define($key, $value);
	}
}
 

“if (isset($_GET['js'])) {“ tells the script that we want JavaScript output from this file, which we’ll call like this:
 
<script type="text/javascript" src="../language/<?php echo LANGUAGE;?>.php?js=1"></script>
 




No Entries Found

Post comment

Name *
Email
Title
Body *
Security code
*
* Required fields

Latest Articles

Top 5 Articles

Programming humor


Collection of funny programming articles
2006-10-08 14:23:43

How to create your own RSS Reader


It is very simple creating your own rss reader, the following article looks at a few methods of doing this.
2008-06-23 13:18:25

Javascript Reference: Dropdown


A quick reference about working with dropdown boxes (select element) in javascript.
2007-02-17 16:36:41

PHP: Snippets


Collection of PHP snippets
2010-05-22 00:06:45

Event driven programming in PHP


An article looking at adding some kind of event driven model to PHP 5
2008-07-28 12:48:09