add_subdirectory(characters)
add_subdirectory(dictionary)
add_subdirectory(konsolesessions)
-add_subdirectory(translator)
+++ /dev/null
-set (krunner_translator_SRCS
- translator.cpp
- translatorjob.cpp
-)
-
-kde4_add_plugin(krunner_translator ${krunner_translator_SRCS})
-target_link_libraries(krunner_translator
- ${KDE4_KDEUI_LIBS}
- ${KDE4_PLASMA_LIBS}
- ${KDE4_KIO_LIBS}
-)
-
-install(
- TARGETS krunner_translator
- DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
-)
-install(
- FILES plasma-runner-translator.desktop
- DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
-)
+++ /dev/null
-#! /usr/bin/env bash
-$XGETTEXT *.cpp -o $podir/plasma_runner_translator.pot
+++ /dev/null
-[Desktop Entry]
-Name=Translator
-Name[ar]=المترجِم
-Name[bs]=Prevodilac
-Name[ca]=Traductor
-Name[ca@valencia]=Traductor
-Name[cs]=Překladatel
-Name[da]=Oversætter
-Name[de]=Übersetzer
-Name[el]=Μεταφραστής
-Name[en_GB]=Translator
-Name[es]=Traductor
-Name[et]=Tõlketeenus
-Name[fi]=Käännin
-Name[fr]=Outil de traduction
-Name[gl]=Tradutor
-Name[hu]=Fordító
-Name[it]=Traduttore
-Name[kk]=Аудару
-Name[ko]=번역기
-Name[nb]=Oversetter
-Name[nds]=Översetter
-Name[nl]=Vertaler
-Name[nn]=Omsetjar
-Name[pl]=Tłumacz
-Name[pt]=Tradutor
-Name[pt_BR]=Tradutor
-Name[ro]=Traducător
-Name[ru]=Переводчик
-Name[sk]=Prekladateľ
-Name[sl]=Prevajalnik
-Name[sr]=преводилац
-Name[sr@ijekavian]=преводилац
-Name[sr@ijekavianlatin]=prevodilac
-Name[sr@latin]=prevodilac
-Name[sv]=Översättning
-Name[tr]=Çevirmen
-Name[ug]=تەرجىمان
-Name[uk]=Перекладач
-Name[x-test]=xxTranslatorxx
-Name[zh_CN]=翻译
-Name[zh_TW]=翻譯器
-Comment=Translates into any language using Google Translate. For list of supported languages visit https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[ar]=ترجم إلى أيّ لغة باستخدام ترجمات جوجل. للحصول على لاحة باللغات المدعومة زُر https://developers.google.com/translate/v2/using_rest?hl=ar#language-params
-Comment[bs]=Prevodi u bilo koji jezik koristeći Google Translate. Za listu podržanih jezika posjetite https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[ca]=Tradueix a qualsevol idioma usant el Google Translate. Per la llista d'idiomes acceptats visiteu https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[ca@valencia]=Tradueix a qualsevol idioma usant el Google Translate. Per la llista d'idiomes acceptats visiteu https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[cs]=Překládá do jakéhokoliv jazyka pomocí Google Translate. Pro seznam podporovaných jazyků navštivte https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[da]=Oversætter til alle sprog med Google Translate. Besøg https://developers.google.com/translate/v2/using_rest?hl=de#language-params for en liste over understøttede sprog
-Comment[de]=Übersetzt mit „Google Übersetzer“ in beliebige Sprachen. Eine Liste der unterstützten Sprachen finden Sie unter https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[el]=Μετάφραση σε οποιαδήποτε γλώσσα με το Google Translate. Για τη λίστα με τις υποστηριζόμενες γλώσσες ανατρέξτε στο https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[en_GB]=Translates into any language using Google Translate. For list of supported languages visit https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[es]=Traduce a cualquier idioma usando Google Translate. Para una lista de los idiomas admitidos visite https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[et]=Tõlgib mis tahes keelde Google Translate'i abil. Toetatud keelte loendi leiab aadressil https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[fi]=Kääntää mille tahansa kielelle käyttäen Google-kääntäjää. Katso tuettujen kielten luettelo osoitteesta https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[fr]=Traduit dans n'importe quelle langue en utilisant « Google Translate ». Pour obtenir une liste des langues prises en charge, veuillez consulter « https://developers.google.com/translate/v2/using_rest?hl=de#language-params »
-Comment[gl]=Traduce a calquera lingua mediante o Google Translate. Para coñecer a lista de linguas admitidas consulte https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[hu]=Lefordítja bármilyen nyelvre a Google Fordító használatával. A támogatott nyelvek listájáért látogassa meg a https://developers.google.com/translate/v2/using_rest?hl=de#language-params oldalt
-Comment[it]=Traduce in qualsiasi lingua utilizzando Google Translate. Per un elenco delle lingue supportate, visita https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[kk]=Google Аудару көмегімен тілден-тілге аудару. Қай тілдер қолдауы барын https://developers.google.com/translate/v2/using_rest?hl=de#language-params дегеннен қараңыз
-Comment[ko]=Google 번역을 사용하여 임의의 언어로 번역합니다. 지원하는 언어 목록은 https://developers.google.com/translate/v2/using_rest?hl=ko#language-params 페이지를 참고하십시오
-Comment[nb]=Oversetter til ethvert språk ved bruk av Google Translate. En liste over språk som er støttet finner du på https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[nds]=Översetten mit "Google Translate". Ünnerstütt Spraken sünd hier oplist: https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[nl]=Vertaalt naar elke taal met Google Translate. Voor een lijst met ondersteunde talen bezoek https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[pl]=Tłumaczy na każdy język przy użyciu Tłumacza Google. Po wykaz obsługiwanych języków odwiedź https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[pt]=Traduz para qualquer língua com o serviço Google Translate. Para uma lista das línguas suportadas, vá a https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[pt_BR]=Traduz para qualquer idioma usando o serviço Google Tradutor. Para ver uma lista com os idiomas suportados, acesse https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[ru]=Перевод на разные языки с помощью Google Translate. Список поддерживаемых языков https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[sk]=Preloží do jazyka pomocou Google Translate. Pre zoznam podporovaných jazykov navštívte https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[sl]=Prevede v katerikoli jezik s pomočjo Google Translate. Za seznam podprtih jezikov obiščite https://developers.google.com/translate/v2/using_rest?hl=sl#language-params
-Comment[sr]=Преводи на разне језике помоћу Гугловог преводиоца. За списак подржаних језика посетите https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[sr@ijekavian]=Преводи на разне језике помоћу Гугловог преводиоца. За списак подржаних језика посетите https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[sr@ijekavianlatin]=Prevodi na razne jezike pomoću Googleovog prevodioca. Za spisak podržanih jezika posetite https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[sr@latin]=Prevodi na razne jezike pomoću Googleovog prevodioca. Za spisak podržanih jezika posetite https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[sv]=Översätter till godtyckligt språk med Google Translate. Besök https://developers.google.com/translate/v2/using_rest#language-params för en lista med språk som stöds.
-Comment[tr]=Google Translate kullanarak herhangi bir dile çevirin. Desteklenen dillerin listesi için https://developers.google.com/translate/v2/using_rest?hl=de#language-params adresini ziyaret edin.
-Comment[uk]=Виконує переклад за допомогою служби Перекладач Google. Зі списком підтримуваних мов можна ознайомитися тут: https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[x-test]=xxTranslates into any language using Google Translate. For list of supported languages visit https://developers.google.com/translate/v2/using_rest?hl=de#language-paramsxx
-Comment[zh_CN]=用谷歌翻译翻译成他国语言支持的语言请参阅https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-Comment[zh_TW]=使用 Google 翻譯來翻譯成任何語言。支援的語言清單請參考 https://developers.google.com/translate/v2/using_rest?hl=de#language-params
-X-KDE-ServiceTypes=Plasma/Runner
-Type=Service
-Icon=applications-education-language
-X-KDE-Library=krunner_translator
-X-KDE-PluginInfo-Author=David Baum
-X-KDE-PluginInfo-Email=david.baum@naraesk.eu
-X-KDE-PluginInfo-Name=translator
-X-KDE-PluginInfo-Version=1.0
-X-KDE-PluginInfo-License=GPL
-X-KDE-PluginInfo-EnabledByDefault=true
+++ /dev/null
-/******************************************************************************
- * Copyright (C) 2013 by David Baum <david.baum@naraesk.eu> *
- * *
- * This library is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU Lesser General Public License as published *
- * by the Free Software Foundation; either version 2 of the License or (at *
- * your option) any later version. *
- * *
- * This library is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Library General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License *
- * along with this library; see the file COPYING.LIB. *
- * If not, see <http://www.gnu.org/licenses/>. *
- *****************************************************************************/
-
-#include "translator.h"
-#include "translatorjob.h"
-
-#include <KDebug>
-#include <KToolInvocation>
-#include <KApplication>
-#include <KRun>
-#include <KIcon>
-
-#include <QtNetwork/QNetworkAccessManager>
-#include <QtNetwork/QNetworkRequest>
-#include <QtNetwork/QNetworkReply>
-#include <QtCore/QRegExp>
-#include <QtCore/QPair>
-#include <QtCore/QObject>
-#include <QtCore/QList>
-#include <QtCore/QEventLoop>
-#include <QtCore/QJsonDocument>
-#include <QtGui/QClipboard>
-
-#include <Plasma/RunnerContext>
-
-
-Translator::Translator(QObject* parent, const QVariantList& args)
- : Plasma::AbstractRunner(parent, args)
-{
- Q_UNUSED(args)
- setObjectName(QLatin1String("Translator"));
- setHasRunOptions(false);
- setIgnoredTypes(Plasma::RunnerContext::Directory |
- Plasma::RunnerContext::File |
- Plasma::RunnerContext::NetworkLocation);
- setSpeed(AbstractRunner::SlowSpeed);
-
- QList<Plasma::RunnerSyntax> syntaxes;
- Plasma::RunnerSyntax autoSyntax(QString::fromLatin1("%1:q:").arg(i18n("<language code>")),
- i18n("Translates the word(s) :q: into target language"));
- syntaxes.append(autoSyntax);
-
- Plasma::RunnerSyntax syntax(QString::fromLatin1("%1:q:").arg(i18n("<source language>-<target language>")),
- i18n("Translates the word(s) :q: from the source into target language"));
- syntaxes.append(syntax);
- setSyntaxes(syntaxes);
-}
-
-Translator::~Translator()
-{
-}
-
-void Translator::match(Plasma::RunnerContext& context)
-{
- QString term = context.query();
- QString text;
- QPair<QString, QString> language;
-
- if (!parseTerm(term, text, language)) {
- return;
- }
-
- if (!context.isValid()) {
- return;
- }
-
- QEventLoop loop;
- TranslatorJob job(text, language);
- connect(&job, SIGNAL(finished()), &loop, SLOT(quit()));
- loop.exec();
-
- parseResult(job.result(), context, text);
-}
-
-void Translator::run(const Plasma::RunnerContext& context, const Plasma::QueryMatch& match)
-{
- Q_UNUSED(context)
- kapp->clipboard()->setText(match.text());
-}
-
-bool Translator::parseTerm(const QString& term, QString& text, QPair<QString, QString> &language)
-{
- int index = term.indexOf(" ");
- if (index == -1) return false;
- text = term.mid(index + 1);
- QString languageTerm = term.left(index);
-
- kDebug() << "text: " << text;
- kDebug() << "lang: " << languageTerm;
-
- if (languageTerm.contains("-")) {
- int index = languageTerm.indexOf("-");
- language.first = languageTerm.left(index);
- language.second = languageTerm.mid(index + 1);
-
- return supportedLanguages.contains(language.first) && supportedLanguages.contains(language.second);
- } else {
- language.first.clear();
- language.second = languageTerm;
- return supportedLanguages.contains(language.second);
- }
-}
-
-void Translator::parseResult(const QString &result, Plasma::RunnerContext& context, const QString &text)
-{
- QString jsonData = result;
- // jsonData contains arrays like this: ["foo",,"bar"]
- // but this is not valid JSON for QJSON, it expects empty strings: ["foo","","bar"]
- jsonData = jsonData.replace(QRegExp(",{3,3}"), ",\"\",\"\",");
- jsonData = jsonData.replace(QRegExp(",{2,2}"), ",\"\",");
- // kDebug() << jsonData;
-
- QJsonDocument jsondoc = QJsonDocument::fromJson(jsonData.toUtf8());
- if (jsondoc.isNull()) {
- return;
- }
-
- bool oldVersion = true;
- QMultiMap<int, QPair<QString, double> > sentences;
-
- QList<Plasma::QueryMatch> matches;
- // we are going recursively through the nested json-array
- // level0 contains the data of the outer array, level1 of the next one and so on
- foreach (const QVariant& level0, jsondoc.toVariant().toList()) {
- QVariantList listLevel0 = level0.toList();
- if (listLevel0.isEmpty()) {
- continue;
- }
- foreach (const QVariant& level1, listLevel0) {
- if (level1.toList().size() <= 2 || level1.toList().at(2).toList().isEmpty()) {
- continue;
- }
- int indexLevel1 = listLevel0.indexOf(level1);
- QVariantList listLevel1 = level1.toList().at(2).toList();
- foreach (const QVariant& level2, listLevel1) {
- QVariantList listLevel2 = level2.toList();
-
- // The JSON we get from Google has not always the same structure.
- // There is a version with addiotanal information like synonyms and frequency,
- // this is called newVersion oldVersion doesn't contain something like this.
-
- bool foundWordNew = (listLevel2.size() > 1) && (!listLevel2.at(1).toList().isEmpty());
- bool foundWordOld = (listLevel2.size() == 4) && (oldVersion == true) && (listLevel2.at(1).toDouble() > 0);
-
- if (foundWordNew || foundWordOld) {
- if (level1.toList().at(0).toString() != text && foundWordOld) {
- // sentences are translated phrase by phrase
- // first we have to add all phrases to sentences and then rebuild them
- sentences.insert(indexLevel1, qMakePair(listLevel2.at(0).toString(), listLevel2.at(1).toDouble() / 1000));
- } else {
- Plasma::QueryMatch match(this);
- match.setType(Plasma::QueryMatch::InformationalMatch);
- match.setIcon(KIcon("applications-education-language"));
- match.setText(listLevel2.at(0).toString());
- kDebug() << "text: " << listLevel2.at(0).toString();
-
- if (foundWordNew) {
- oldVersion = false;
- kDebug() << "Subtext: ";
- match.setSubtext(level1.toList().at(0).toString());
- kDebug() << level1.toList().at(0).toString();
- if (listLevel2.size() > 3) {
- kDebug() << "Relevance: ";
- match.setRelevance(listLevel2.at(3).toDouble());
- kDebug() << listLevel2.at(3).toDouble();
- } else {
- match.setRelevance(0.0001);
- }
- } else {
- kDebug() << "Relevance: ";
- match.setRelevance(listLevel2.at(1).toDouble() / 1000);
- kDebug() << listLevel2.at(1).toDouble() / 1000;
- }
-
- matches.append(match);
- }
- }
- }
- }
- }
-
- if (!sentences.isEmpty()) {
- QPair<QString, double> pair;
- QMapIterator<int, QPair<QString, double> > it(sentences);
- int currentKey = -1;
- double currentRel = 1;
- QString currentString;
-
- while (it.hasNext()) {
- pair = it.next().value();
-
- // we're on to another key, process previous results, if any
- if (currentKey != it.key()) {
-
- currentKey = it.key();
- currentRel = 1;
- currentString.append(' ').append(pair.first);
- currentRel *= pair.second;
- }
- }
- if (!currentString.isEmpty()) {
- Plasma::QueryMatch match(this);
- match.setType(Plasma::QueryMatch::InformationalMatch);
- match.setIcon(KIcon("applications-education-language"));
- match.setText(currentString);
- match.setRelevance(currentRel);
- matches.append(match);
-
- }
- }
-
- context.addMatches(context.query(), matches);
-}
-
-// https://cloud.google.com/translate/docs/basic/translating-text#language-params
-
-const QSet<QString> Translator::supportedLanguages = QSet<QString>() << "af" << "sq" << "ar" << "az"
- << "eu" << "bn" << "be" << "bg" << "ca" << "zh-CN" << "zh-TW" << "hr" << "cs"
- << "da" << "nl" << "en" << "eo" << "et" << "tl" << "fi" << "fr" << "gl"
- << "ka" << "de" << "el" << "gu" << "ht" << "iw" << "hi" << "hu" << "is"
- << "id" << "ga" << "it" << "ja" << "kn" << "ko" << "la" << "lv" << "lt"
- << "mk" << "ms" << "mt" << "no" << "fa" << "pl" << "pt" << "ro" << "ru"
- << "sr" << "sk" << "sl" << "es" << "sw" << "sv" << "ta" << "te" << "th"
- << "tr" << "uk" << "ur" << "vi" << "cy" << "yi";
-
-#include "moc_translator.cpp"
+++ /dev/null
-/******************************************************************************
- * Copyright (C) 2013 by David Baum <david.baum@naraesk.eu> *
- * *
- * This library is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU Lesser General Public License as published *
- * by the Free Software Foundation; either version 2 of the License or (at *
- * your option) any later version. *
- * *
- * This library is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Library General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License *
- * along with this library; see the file COPYING.LIB. *
- * If not, see <http://www.gnu.org/licenses/>. *
- *****************************************************************************/
-
-#ifndef TRANSLATOR_H
-#define TRANSLATOR_H
-
-#include <Plasma/AbstractRunner>
-
-/**
- * Translate a word or sentence using google translate service http://translate.google.com/
- */
-class Translator : public Plasma::AbstractRunner
-{
-
- Q_OBJECT
-
-public:
- Translator(QObject *parent, const QVariantList &args);
- ~Translator();
-
- void match(Plasma::RunnerContext &);
- void run(const Plasma::RunnerContext &, const Plasma::QueryMatch &);
-
-Q_SIGNALS:
- void matchMade(Plasma::RunnerContext *);
-
-private:
- bool parseTerm(const QString &, QString &, QPair<QString, QString> &);
- void parseResult(const QString &, Plasma::RunnerContext &, const QString &);
- static const QSet<QString> supportedLanguages;
-};
-
-K_EXPORT_PLASMA_RUNNER(translator, Translator)
-
-#endif
+++ /dev/null
-/******************************************************************************
- * Copyright (C) 2013 by David Baum <david.baum@naraesk.eu> *
- * *
- * This library is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU Lesser General Public License as published *
- * by the Free Software Foundation; either version 2 of the License or (at *
- * your option) any later version. *
- * *
- * This library is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Library General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License *
- * along with this library; see the file COPYING.LIB. *
- * If not, see <http://www.gnu.org/licenses/>. *
- *****************************************************************************/
-
-#include "translatorjob.h"
-
-TranslatorJob::TranslatorJob(const QString &text, const QPair<QString, QString> &language)
- : m_manager(0)
-{
- m_manager = new QNetworkAccessManager(this);
-
- QNetworkRequest request(QUrl("http://www.google.com/translate_a/t"));
- request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
-
- QUrl postData;
- postData.addQueryItem("client", "t");
- postData.addQueryItem("sl", language.first);
- postData.addQueryItem("tl", language.second);
- postData.addQueryItem("text", text);
-
- m_manager->post(request, postData.encodedQuery());
- connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(jobCompleted(QNetworkReply*)));
-}
-
-void TranslatorJob::jobCompleted(QNetworkReply* reply)
-{
- m_result = QString::fromUtf8(reply->readAll());
- reply->deleteLater();
- emit finished();
-}
-
-QString TranslatorJob::result() const
-{
- return m_result;
-}
+++ /dev/null
-/******************************************************************************
- * Copyright (C) 2013 by David Baum <david.baum@naraesk.eu> *
- * *
- * This library is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU Lesser General Public License as published *
- * by the Free Software Foundation; either version 2 of the License or (at *
- * your option) any later version. *
- * *
- * This library is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Library General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License *
- * along with this library; see the file COPYING.LIB. *
- * If not, see <http://www.gnu.org/licenses/>. *
- *****************************************************************************/
-
-#ifndef TRANSLATORJOB_H
-#define TRANSLATORJOB_H
-
-#include <QtNetwork/QNetworkReply>
-
-#include <QNetworkReply>
-#include <QNetworkAccessManager>
-
-class TranslatorJob : public QObject
-{
- Q_OBJECT
-public:
- TranslatorJob(const QString &, const QPair<QString, QString> &);
- QString result() const;
- void start();
-
-private Q_SLOTS:
- void jobCompleted(QNetworkReply *);
-
-Q_SIGNALS:
- void finished();
-
-private:
- QNetworkAccessManager *m_manager;
- QString m_result;
-};
-
-#endif