TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-28-2008, 09:16 AM   #1 (permalink)
The Wanderer
 
rupam_jaiswal's Avatar
 
Join Date: Jun 2008
Posts: 8
Thanks: 0
rupam_jaiswal is on a distinguished road
Default 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????
rupam_jaiswal is offline  
Reply With Quote
Old 08-28-2008, 01:13 PM   #2 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 21
Thanks: 0
Speeple is on a distinguished road
Default

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
__________________
AKA Martin Gallagher
Speeple is offline  
Reply With Quote
Old 09-01-2008, 07:54 PM   #3 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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();

__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:17 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design