TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   language converter in php (http://www.talkphp.com/advanced-php-programming/3294-language-converter-php.html)

rupam_jaiswal 08-28-2008 09:16 AM

language converter in php
 
Hi,
I have to make a language (literal) converter in php from english to hindi.
i dont want the hindi translation of the word. just typing the same words in hindi
if i type 'baloon' in english, it will convert as it is into hindi ( बलून ) ्
I mean it only typing word 'baloon' in hindi using hindi letters rather than english.
any idea????

Speeple 08-28-2008 01:13 PM

You mean a dictionary not a true translation of sentences.

I don't know if there is any free data out there, there are similar services online tho which might have an API:

Search: hindi dictionary - Google Search

This looks like what you want: Shabdanjali - English Hindi Dictionary | www.shabdkosh.com

The coverage of words might small tho.

More: hindi dictionary download gpl - Google Search

sketchMedia 09-01-2008 07:54 PM

Dunno if this will be of any use, but i have quickly botched a class to translate words using Google Translate.

Its a bit of a mess but it works, it also uses CURL and PHP DOM XPath.

PHP Code:

<?php
error_reporting
(0);
class 
translatorException extends Exception {}
class 
translator
{
    private 
$m_szLangPair;
    private 
$m_szText;
    const 
BASE_URL 'http://translate.google.com/translate_t?langpair=';

    private function 
throwException($szMessage) { throw new translatorException($szMessage); }

    private function 
getHTML()
    {
        
$pCurl curl_init(self::BASE_URL $this->m_szLangPair);
        
        
curl_setopt($pCurlCURLOPT_RETURNTRANSFER1);
        
curl_setopt($pCurlCURLOPT_HEADER1);
        
curl_setopt($pCurlCURLOPT_FOLLOWLOCATION1);
        
curl_setopt($pCurlCURLOPT_TIMEOUT15);
        
curl_setopt($pCurlCURLOPT_POST1);
        
curl_setopt($pCurlCURLOPT_POSTFIELDS'text=' $this->m_szText);
        
        
$szHtml curl_exec($pCurl);
        
        if(
$szError curl_error($pCurl))
        {
            
curl_close ($pCurl); 
            
$this->throwException($szError);
        }
        return 
$szHtml;
    }
    
    public function 
__call($szCall$aArgs)
    {
        
preg_match('/^([a-z]{2})2([a-z]{2})$/i'$szCall$aMatches)
            or 
$this->throwException('Malformed system call, 
                                      [lang]2[lang] e.g. en2it (ENglish to ITalian)'
);

        
$this->m_szLangPair urlencode($aMatches[1] . '|' $aMatches[2]) . '&';
        
        
is_null($aArgs) || !is_array(reset($aArgs))
            or 
$this->throwException('You have entered either a NULL or incompatable type into the system, 
                                      please only pass in a string to be converted'
);
            
        
$this->m_szText urlencode((string)reset($aArgs));
        
        
$pDoc = new DomDocument;
        
$pDoc->loadHTML($this->getHTML());
        
$pXpath = new DOMXPath($pDoc);
        
        return 
$pXpath->query('//div[@id="result_box"]')->item(0)->nodeValue;
    }
}

To use:
PHP Code:

try
{
    
$lang = new translator;
    
header('Content-type: text/html; charset="utf-8"');
    echo 
$lang->en2hi('hello');
}
catch (
Exception $e)
{
    echo 
$e->getMessage();




All times are GMT. The time now is 11:45 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0