Qt4 Google Services: Translator, Spell Checker and more…

June 6, 2009 Matteo Bertozzi | Filed Under Qt4 | No Comments

Last month I’ve made a simple wrapper for Google Authentication, Today I’ve written other 4 classes to wrap the Google’s Translator, Language Detector, Suggestions and the Spell Checker Services.

Translator Example

QEventLoop l;
THGoogleTranslator gTranslator;
connect(&gTranslator, SIGNAL(finished(bool)), &l, SLOT(quit()));
gTranslator.setDestinationLanguage("en");
gTranslator.translate("Ciao");
l.exec();

qDebug() << gTranslator.translatedText(); // Maybe "Hello"
qDebug() << gTranslator.detectedSourceLanguage(); // Maybe "it"

Suggest Example

QEventLoop l;
THGoogleSuggest gSuggest;
connect(&gSuggest, SIGNAL(finished(bool)), &l, SLOT(quit()));
gSuggest.suggest("Qt Softw");
l.exec();

qDebug() << gSuggest.suggestions();
// ("qt software", "qt software download", "qt software gpl exception", ...)

Spell Checker Example

QEventLoop l;
THGoogleSpellChecker gSpellChecker;
connect(&gSpellChecker, SIGNAL(finished(bool)), &l, SLOT(quit()));
gSpellChecker.spellCheck("Gogl Spll");
l.exec();

// "Gogl" ("Google", "Gogol", "Gog", "Goal", "Gog's")
// "Spll" ("Spell", "Sp ll", "Sp-ll", "Spill", "Sell")
foreach (QString original, gSpellChecker.keys())
    qDebug() << original << gSpellChecker.suggestions(original);

Language Detector Example

QEventLoop l;
THGoogleDetectLanguage gDetectLang;
connect(&gDetectLang, SIGNAL(finished(bool)), &l, SLOT(quit()));
gDetectLang.detectLanguage("Ciao");
l.exec();

qDebug() << "Query" << gDetectLang.query();
qDebug() << "Language" << gDetectLang.language(); // Maybe "it"
qDebug() << "Is Reliable" << gDetectLang.isReliable();
qDebug() << "Confidence" << gDetectLang.confidence();

You can find the source at GitHub (Git WebView) or you can download the source code Here: Qt4 Google Services Take 2 Source Code.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>