开发者

how to write code for multilingual in php [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

How to write code for multilingual in php?

Can you please explain me how to use the following php code ? I am not sure if i execute it properly... All file .php are on same directory. When i try to execute decide-lang.php, i got ( ! ) NOTICE: Undefined variable:_Get in c:\wamp\www\lang\decide-lang.php on line 2

Thanks.

    ///////////////////////////////
index.php
//////////////////////////////
<?php  
require("decide-lang.php");  
?>  
<html><title>Exercice </title>  
<body>  
<?php echo TXT_INDEX; ?>  
<p><br>
  News: <?php echo TXT_NEWS; ?> <br>
  Conseil du jour: <?php echo TXT_CONSEIL_INDEX ; ?> </p>
<p>&nbsp;</p>
<p><a href="index.php?la开发者_开发知识库ng=en">Not french??</a></p>
</body>  
</html>  


//////////////////////////////
decide-lang.php
//////////////////////////////
<?php  
if ($lang=='fr') {           // si la langue est 'fr' (français) on inclut le fichier fr-lang.php  
include('fr-lang.php');  
}   
else if ($lang=='en') {      // si la langue est 'en' (anglais) on inclut le fichier en-lang.php  
include('en-lang.php');  
}  
else {                       // si aucune langue n'est déclarée on inclut le fichier fr-lang.php par défaut  
include('fr-lang.php');  
}  

?>  

//////////////////////////////
en-lang.php
/////////////////////////////
<?php  
define('TXT_INDEX', 'Welcome on YOu_Site.com!');  
define('TXT_NEWS', 'The sun is shining !');  
define('TXT_CONSEIL_INDEX', 'Lets do some PHP !');  
?> 
//////////////////////////////
fr-lang.php
/////////////////////////////
<?php  
define('TXT_INDEX', 'Bienvenue sur votre_site.com !');  
define('TXT_NEWS', 'Il fait un soleil radieux !');  
define('TXT_CONSEIL_INDEX', 'Faites du PHP !');  

?>


I suggest use Zend_translate http://framework.zend.com/manual/en/zend.translate.html

it has great support for multilingual It is not necessary to use it with zend framework you can also use it as independent module in your php project

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜