I want to add a feature in which my website can translate from English to Hindi..

How it can done and there is any free script ?

is your website a CMS or a custom developed website ?

This is a function that I've used a while back in a Class.
You have to generate your language files like en.txt or de.txt.

In your PHP code you will call the function and the string $contet->__('translate me');
In your de.txt you will have on each line a separate text.

translate me=übersetzen mich

You will have to set your language based on your user settings.

        $language = $this->selectLanguage();
        $this->language = $language;

Then call the following function with $content->__('translate me'); and you should have your text translated.

    public function findString($str) {
        if (array_key_exists($str, $this->lang[$this->language])) {
            return $this->lang[$this->language][$str];
        }
        return $str;
    }


    /**
    * after the text is found your explode it by =
    * @param string $str
    * @returneaza Returns the exploded string 
    */
    public function splitStrings($str) {
        return explode('=',trim($str));
    }


    /** 
    * Function that translates the text  
    * it the words/translation are found, if not, default language will be the written native language
    * @param string $str
    * @returneaza returns a translaton trough splitString();
    */
    public function __($str) {    
        if (!array_key_exists($this->language, $this->lang)) {
            if (file_exists($this->language.'.txt')) {
                $strings = array_map(array($this,'splitStrings'),file($this->language.'.txt'));
                foreach ($strings as $k => $v) {
                    $this->lang[$this->language][$v[0]] = $v[1];
                }
                return $this->findString($str);
            }
            else {
                return $str;
            }
        }
        else {
            return $this->findString($str);
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.