开发者

Website Language translation in php

Hi i am devloping site in php i ne开发者_如何学编程ed to translate whole website in other language like german,spanish etc... how can it possible in php i have tried using some csv but it all goes static i mean i can not convert the whole website ..

if you have any csv or api information ..

please help..

-Div


<?php
    $GLOBAL['langs']=array(
       'en'=>array(
          'Welcome to my site!'=>'Welcome to my site!'
       ),
       'it'=>array(
          'Welcome to my site!'=>'Benvenuto sul mio sito web!'
       )
    );

    function _($text){
       $lang=$_COOKIE['lang'];
       return $GLOBAL['langs'][$text];
    }
?><html><head><?php

    echo '<title>'._('Welcome to my site!').'</title>';

?></head><body>

    ....

</body></html>


While Christian's answer will do the trick there's a more cleaner and efficient way to achieve your needs: gettext is PHP's built-in function for internationalization.


Zend Translate is a library exactly build for this.

Gettext is not thread-safe. PHP supports only gettext and native array. Zend_Translate supports several source formats, including those supported by PHP, and other formats including TMX and CSV files.


If you want to translate 'a whole page' to any language, you could use Google Translate.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜