Below is the sample implementation of LOCALIZATION using PHP
FILE 1: en_US.php
<?
$helloworld="Hello World ";
?>
FILE 2: fr_CA.php
<?
$helloworld="Bonjour le Monde ";
?>
FILE 3: Localization.php
<?php
class Localization
{
var $country;
var $language;
function Localization($language,$country)
{
$this->country=$country;
$this->language=$language;
}
function Translate($str)
{
include ($this->language)."_".($this->country).".inc";
return $$str;
}
}
?>
File 4: index.php
<?php include "Localization.php" ?>
<html>
<head>
</head>
<body>
This is in American English
<br>
<br>
<font color="red"><b>
<?
$locEn=new Localization("en","US");
print($locEn->Translate("helloworld"));
?>
</b></font>
<hr>
This is in Canadian French
<br>
<br>
<font color="darkgreen"><b>
<?
$locFr=new Localization("fr","CA");
print($locFr->Translate("helloworld"));
?>
</b>
</font>
</body>
</html>
FILE 1: en_US.php
<?
$helloworld="Hello World ";
?>
FILE 2: fr_CA.php
<?
$helloworld="Bonjour le Monde ";
?>
FILE 3: Localization.php
<?php
class Localization
{
var $country;
var $language;
function Localization($language,$country)
{
$this->country=$country;
$this->language=$language;
}
function Translate($str)
{
include ($this->language)."_".($this->country).".inc";
return $$str;
}
}
?>
File 4: index.php
<?php include "Localization.php" ?>
<html>
<head>
</head>
<body>
This is in American English
<br>
<br>
<font color="red"><b>
<?
$locEn=new Localization("en","US");
print($locEn->Translate("helloworld"));
?>
</b></font>
<hr>
This is in Canadian French
<br>
<br>
<font color="darkgreen"><b>
<?
$locFr=new Localization("fr","CA");
print($locFr->Translate("helloworld"));
?>
</b>
</font>
</body>
</html>
No comments:
Post a Comment