views:

63

answers:

4

Hi i am devloping site in php i need 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

+1  A: 
<?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>
Christian Sciberras
It's `$GLOBALS`, not `$GLOBAL`.
Lekensteyn
Using `_()` might be a problem if your PHP has *gettext* support enabled as this is an alias to `gettext()`, which is also a method for localization. http://php.net/manual/en/function.gettext.php
Archimedix
A: 

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

Lekensteyn
A: 

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.

fabrik
A: 

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.

Elzo Valugi
Unfortunately the guys of the Zend-Framework don't even know themselves which components are related with each other. So best practice is to install the whole Zend-Framework. Which means very much files and a slight Overkill I would say. But for Applications built upon Zend-Framework, Zend_Translate is a good solution, of course.
faileN
I disagree. You can check the dependencies here, both to PHP packages and internal ZF. http://framework.zend.com/manual/en/requirements.introduction.html
Elzo Valugi