LanguageHelper added

This commit is contained in:
Gres 2014-04-04 18:39:10 +04:00
parent 2d9c139c02
commit e7e74ed20e
8 changed files with 305 additions and 201 deletions

225
LanguageHelper.cpp Normal file
View File

@ -0,0 +1,225 @@
#include <QDir>
#include <QSettings>
#include "LanguageHelper.h"
#include "Settings.h"
LanguageHelper::LanguageHelper()
{
init ();
}
QStringList LanguageHelper::availableOcrLanguagesUi() const
{
QStringList uiItems;
foreach (const QString& item, availableOcrLanguages_)
{
uiItems << ocrCodeToUi (item);
}
uiItems.sort ();
return uiItems;
}
const QStringList &LanguageHelper::availableOcrLanguages() const
{
return availableOcrLanguages_;
}
QStringList LanguageHelper::translateLanguagesUi() const
{
QStringList uiItems = translateLanguages_.keys ();
uiItems.sort ();
return uiItems;
}
QStringList LanguageHelper::translateLanguages() const
{
return translateLanguages_.values ();
}
QString LanguageHelper::translateCodeToUi(const QString &text) const
{
return translateLanguages_.key (text, text);
}
QString LanguageHelper::translateUiToCode(const QString &text) const
{
return translateLanguages_.value (text, text);
}
QString LanguageHelper::ocrCodeToUi(const QString &text) const
{
return ocrLanguages_.key (text, text);
}
QString LanguageHelper::ocrUiToCode(const QString &text) const
{
return ocrLanguages_.value (text, text);
}
QString LanguageHelper::translateForOcrCode(const QString &text) const
{
QString ocrUi = ocrUiToCode (text);
QString translate = translateCodeToUi (ocrUi);
if (translate == ocrUi)
{
translate = "auto";
}
return translate;
}
void LanguageHelper::init()
{
initOcrLanguages ();
initTranslateLanguages ();
updateAvailableOcrLanguages ();
}
void LanguageHelper::updateAvailableOcrLanguages()
{
QSettings settings;
settings.beginGroup (settings_names::recogntionGroup);
QString tessDataPlace = settings.value (settings_names::tessDataPlace,
settings_values::tessDataPlace).toString ();
QDir dir (tessDataPlace + "/tessdata/");
if (!dir.exists ())
{
return;
}
availableOcrLanguages_.clear ();
QStringList files = dir.entryList (QStringList () << "*.traineddata", QDir::Files);
foreach (const QString& file, files)
{
QString lang = file.left (file.indexOf ("."));
availableOcrLanguages_ << lang;
}
}
void LanguageHelper::initTranslateLanguages()
{
translateLanguages_.insert(QObject::tr("Afrikaans"),"af");
translateLanguages_.insert(QObject::tr("Albanian"),"sq");
translateLanguages_.insert(QObject::tr("Arabic"),"ar");
translateLanguages_.insert(QObject::tr("Armenian"),"hy");
translateLanguages_.insert(QObject::tr("Azerbaijani"),"az");
translateLanguages_.insert(QObject::tr("Basque"),"eu");
translateLanguages_.insert(QObject::tr("Belarusian"),"be");
translateLanguages_.insert(QObject::tr("Bulgarian"),"bg");
translateLanguages_.insert(QObject::tr("Catalan"),"ca");
translateLanguages_.insert(QObject::tr("Chinese (Simplified)"),"zh-CN");
translateLanguages_.insert(QObject::tr("Chinese (Traditional)"),"zh-TW");
translateLanguages_.insert(QObject::tr("Croatian"),"hr");
translateLanguages_.insert(QObject::tr("Czech"),"cs");
translateLanguages_.insert(QObject::tr("Danish"),"da");
translateLanguages_.insert(QObject::tr("Dutch"),"nl");
translateLanguages_.insert(QObject::tr("English"),"en");
translateLanguages_.insert(QObject::tr("Estonian"),"et");
translateLanguages_.insert(QObject::tr("Filipino"),"tl");
translateLanguages_.insert(QObject::tr("Finnish"),"fi");
translateLanguages_.insert(QObject::tr("French"),"fr");
translateLanguages_.insert(QObject::tr("Galician"),"gl");
translateLanguages_.insert(QObject::tr("Georgian"),"ka");
translateLanguages_.insert(QObject::tr("German"),"de");
translateLanguages_.insert(QObject::tr("Greek"),"el");
translateLanguages_.insert(QObject::tr("Haitian Creole"),"ht");
translateLanguages_.insert(QObject::tr("Hebrew"),"iw");
translateLanguages_.insert(QObject::tr("Hindi"),"hi");
translateLanguages_.insert(QObject::tr("Hungarian"),"hu");
translateLanguages_.insert(QObject::tr("Icelandic"),"is");
translateLanguages_.insert(QObject::tr("Indonesian"),"id");
translateLanguages_.insert(QObject::tr("Irish"),"ga");
translateLanguages_.insert(QObject::tr("Italian"),"it");
translateLanguages_.insert(QObject::tr("Japanese"),"ja");
translateLanguages_.insert(QObject::tr("Korean"),"ko");
translateLanguages_.insert(QObject::tr("Latvian"),"lv");
translateLanguages_.insert(QObject::tr("Lithuanian"),"lt");
translateLanguages_.insert(QObject::tr("Macedonian"),"mk");
translateLanguages_.insert(QObject::tr("Malay"),"ms");
translateLanguages_.insert(QObject::tr("Maltese"),"mt");
translateLanguages_.insert(QObject::tr("Norwegian"),"no");
translateLanguages_.insert(QObject::tr("Persian"),"fa");
translateLanguages_.insert(QObject::tr("Polish"),"pl");
translateLanguages_.insert(QObject::tr("Portuguese"),"pt");
translateLanguages_.insert(QObject::tr("Romanian"),"ro");
translateLanguages_.insert(QObject::tr("Russian"),"ru");
translateLanguages_.insert(QObject::tr("Serbian"),"sr");
translateLanguages_.insert(QObject::tr("Slovak"),"sk");
translateLanguages_.insert(QObject::tr("Slovenian"),"sl");
translateLanguages_.insert(QObject::tr("Spanish"),"es");
translateLanguages_.insert(QObject::tr("Swahili"),"sw");
translateLanguages_.insert(QObject::tr("Swedish"),"sv");
translateLanguages_.insert(QObject::tr("Thai"),"th");
translateLanguages_.insert(QObject::tr("Turkish"),"tr");
translateLanguages_.insert(QObject::tr("Ukrainian"),"uk");
translateLanguages_.insert(QObject::tr("Urdu"),"ur");
translateLanguages_.insert(QObject::tr("Vietnamese"),"vi");
translateLanguages_.insert(QObject::tr("Welsh"),"cy");
translateLanguages_.insert(QObject::tr("Yiddish"),"yi");
}
void LanguageHelper::initOcrLanguages()
{
ocrLanguages_.insert(QObject::tr("Ancient Greek"),"grc");
ocrLanguages_.insert(QObject::tr("Esperanto alternative"),"epo_alt");
ocrLanguages_.insert(QObject::tr("English"),"eng");
ocrLanguages_.insert(QObject::tr("Ukrainian"),"ukr");
ocrLanguages_.insert(QObject::tr("Turkish"),"tur");
ocrLanguages_.insert(QObject::tr("Thai"),"tha");
ocrLanguages_.insert(QObject::tr("Tagalog"),"tgl");
ocrLanguages_.insert(QObject::tr("Telugu"),"tel");
ocrLanguages_.insert(QObject::tr("Tamil"),"tam");
ocrLanguages_.insert(QObject::tr("Swedish"),"swe");
ocrLanguages_.insert(QObject::tr("Swahili"),"swa");
ocrLanguages_.insert(QObject::tr("Serbian"),"srp");
ocrLanguages_.insert(QObject::tr("Albanian"),"sqi");
ocrLanguages_.insert(QObject::tr("Spanish"),"spa");
ocrLanguages_.insert(QObject::tr("Slovenian"),"slv");
ocrLanguages_.insert(QObject::tr("Slovakian"),"slk");
ocrLanguages_.insert(QObject::tr("Romanian"),"ron");
ocrLanguages_.insert(QObject::tr("Portuguese"),"por");
ocrLanguages_.insert(QObject::tr("Polish"),"pol");
ocrLanguages_.insert(QObject::tr("Norwegian"),"nor");
ocrLanguages_.insert(QObject::tr("Dutch"),"nld");
ocrLanguages_.insert(QObject::tr("Malay"),"msa");
ocrLanguages_.insert(QObject::tr("Maltese"),"mlt");
ocrLanguages_.insert(QObject::tr("Macedonian"),"mkd");
ocrLanguages_.insert(QObject::tr("Malayalam"),"mal");
ocrLanguages_.insert(QObject::tr("Lithuanian"),"lit");
ocrLanguages_.insert(QObject::tr("Latvian"),"lav");
ocrLanguages_.insert(QObject::tr("Korean"),"kor");
ocrLanguages_.insert(QObject::tr("Kannada"),"kan");
ocrLanguages_.insert(QObject::tr("Italian"),"ita");
ocrLanguages_.insert(QObject::tr("Icelandic"),"isl");
ocrLanguages_.insert(QObject::tr("Indonesian"),"ind");
ocrLanguages_.insert(QObject::tr("Cherokee"),"chr");
ocrLanguages_.insert(QObject::tr("Hungarian"),"hun");
ocrLanguages_.insert(QObject::tr("Croatian"),"hrv");
ocrLanguages_.insert(QObject::tr("Hindi"),"hin");
ocrLanguages_.insert(QObject::tr("Hebrew"),"heb");
ocrLanguages_.insert(QObject::tr("Galician"),"glg");
ocrLanguages_.insert(QObject::tr("Middle French (ca. 1400-1600)"),"frm");
ocrLanguages_.insert(QObject::tr("Frankish"),"frk");
ocrLanguages_.insert(QObject::tr("French"),"fra");
ocrLanguages_.insert(QObject::tr("Finnish"),"fin");
ocrLanguages_.insert(QObject::tr("Basque"),"eus");
ocrLanguages_.insert(QObject::tr("Estonian"),"est");
ocrLanguages_.insert(QObject::tr("Math / equation"),"equ");
ocrLanguages_.insert(QObject::tr("Esperanto"),"epo");
ocrLanguages_.insert(QObject::tr("Middle English (1100-1500)"),"enm");
ocrLanguages_.insert(QObject::tr("Greek"),"ell");
ocrLanguages_.insert(QObject::tr("German"),"deu");
ocrLanguages_.insert(QObject::tr("Danish"),"dan");
ocrLanguages_.insert(QObject::tr("Czech"),"ces");
ocrLanguages_.insert(QObject::tr("Catalan"),"cat");
ocrLanguages_.insert(QObject::tr("Bulgarian"),"bul");
ocrLanguages_.insert(QObject::tr("Bengali"),"ben");
ocrLanguages_.insert(QObject::tr("Belarusian"),"bel");
ocrLanguages_.insert(QObject::tr("Azerbaijani"),"aze");
ocrLanguages_.insert(QObject::tr("Arabic"),"ara");
ocrLanguages_.insert(QObject::tr("Afrikaans"),"afr");
ocrLanguages_.insert(QObject::tr("Japanese"),"jpn");
ocrLanguages_.insert(QObject::tr("Chinese (Simplified)"),"chi_sim");
ocrLanguages_.insert(QObject::tr("Chinese (Traditional)"),"chi_tra");
ocrLanguages_.insert(QObject::tr("Russian"),"rus");
ocrLanguages_.insert(QObject::tr("Vietnamese"),"vie");
}

37
LanguageHelper.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef LANGUAGEHELPER_H
#define LANGUAGEHELPER_H
#include <QMap>
#include <QStringList>
class LanguageHelper
{
public:
LanguageHelper ();
QStringList availableOcrLanguagesUi () const;
const QStringList& availableOcrLanguages () const;
QStringList translateLanguagesUi () const;
QStringList translateLanguages () const;
QString translateCodeToUi (const QString& text) const;
QString translateUiToCode (const QString& text) const;
QString ocrCodeToUi (const QString& text) const;
QString ocrUiToCode (const QString& text) const;
QString translateForOcrCode (const QString& text) const;
void updateAvailableOcrLanguages ();
private:
void init ();
void initTranslateLanguages ();
void initOcrLanguages ();
private:
QStringList availableOcrLanguages_;
QMap<QString, QString> translateLanguages_;
QMap<QString, QString> ocrLanguages_;
};
#endif // LANGUAGEHELPER_H

View File

@ -17,11 +17,13 @@
#include "Recognizer.h"
#include "Translator.h"
#include "ResultDialog.h"
#include "LanguageHelper.h"
Manager::Manager(QObject *parent) :
QObject(parent),
trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)),
selection_ (new SelectionDialog),
dictionary_ (new LanguageHelper),
selection_ (new SelectionDialog (*dictionary_)),
resultDialog_ (new ResultDialog),
captureAction_ (NULL), repeatAction_ (NULL), clipboardAction_ (NULL),
useResultDialog_ (true)
@ -60,6 +62,7 @@ Manager::Manager(QObject *parent) :
connect (this, SIGNAL (showPixmap (QPixmap)),
selection_, SLOT (setPixmap (QPixmap)));
connect (this, SIGNAL (settingsEdited ()), selection_, SLOT (updateMenu ()));
connect (this, SIGNAL (settingsEdited ()), this, SLOT (applySettings ()));
selection_->setWindowIcon (trayIcon_->icon ());
resultDialog_->setWindowIcon (trayIcon_->icon ());
@ -117,6 +120,9 @@ void Manager::applySettings()
// Depends on SettingsEditor button indexes. 1==dialog
useResultDialog_ = settings.value (settings_names::resultShowType,
settings_values::resultShowType).toBool ();
Q_CHECK_PTR (dictionary_);
dictionary_->updateAvailableOcrLanguages ();
}
Manager::~Manager()
@ -137,7 +143,7 @@ void Manager::capture()
void Manager::settings()
{
SettingsEditor editor;
SettingsEditor editor (*dictionary_);
editor.setWindowIcon (trayIcon_->icon ());
connect (&editor, SIGNAL (settingsEdited ()), SIGNAL (settingsEdited ()));
editor.exec ();

View File

@ -11,6 +11,7 @@ class QMenu;
class SelectionDialog;
class ResultDialog;
class LanguageHelper;
class Manager : public QObject
{
@ -43,6 +44,7 @@ class Manager : public QObject
private:
QSystemTrayIcon* trayIcon_;
LanguageHelper* dictionary_;
SelectionDialog* selection_;
ResultDialog* resultDialog_;
QAction* captureAction_;

View File

@ -10,6 +10,9 @@ struct ProcessingItem
QString recognized;
QString translated;
QString ocrLanguage;
QString sourceLanguage;
bool isValid () const;
};
Q_DECLARE_METATYPE(ProcessingItem)

View File

@ -24,7 +24,8 @@ SOURCES += main.cpp\
Translator.cpp \
ResultDialog.cpp \
ProcessingItem.cpp \
ImageProcessing.cpp
ImageProcessing.cpp \
LanguageHelper.cpp
HEADERS += \
Manager.h \
@ -36,7 +37,8 @@ HEADERS += \
Settings.h \
ProcessingItem.h \
ResultDialog.h \
ImageProcessing.h
ImageProcessing.h \
LanguageHelper.h
FORMS += \
SettingsEditor.ui \

View File

@ -1,16 +1,15 @@
#include "SettingsEditor.h"
#include "ui_SettingsEditor.h"
#include "LanguageHelper.h"
#include <QSettings>
#include <QFileDialog>
#include "Settings.h"
SettingsEditor::SettingsEditor(QWidget *parent) :
SettingsEditor::SettingsEditor(const LanguageHelper &dictionary, QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsEditor),
ui(new Ui::SettingsEditor), dictionary_ (dictionary),
buttonGroup_ (new QButtonGroup (this))
{
ui->setupUi(this);
@ -22,9 +21,7 @@ SettingsEditor::SettingsEditor(QWidget *parent) :
connect (ui->tessdataEdit, SIGNAL (textChanged (const QString&)),
SLOT (initOcrLangCombo ()));
initTranslateLanguages ();
ui->translateLangCombo->addItems (translateLanguages_.keys ());
initOcrLanguages ();
ui->translateLangCombo->addItems (dictionary_.translateLanguagesUi ());
loadSettings ();
loadState ();
}
@ -58,23 +55,16 @@ void SettingsEditor::saveSettings() const
settings.beginGroup (settings_names::recogntionGroup);
settings.setValue (settings_names::tessDataPlace, ui->tessdataEdit->text ());
QString uiOcrLanguage = ui->ocrLangCombo->currentText ();
QString settingsOcrLanguage = ocrLanguages_.value (uiOcrLanguage, uiOcrLanguage);
settings.setValue (settings_names::ocrLanguage, settingsOcrLanguage);
QString ocrLanguage = dictionary_.ocrUiToCode (ui->ocrLangCombo->currentText ());
settings.setValue (settings_names::ocrLanguage, ocrLanguage);
settings.setValue (settings_names::imageScale, ui->imageScaleSpin->value ());
settings.endGroup ();
settings.beginGroup (settings_names::translationGroup);
Q_ASSERT (translateLanguages_.contains (ui->translateLangCombo->currentText ()));
QString uiTranslateLanguage = ui->translateLangCombo->currentText ();
QString settingsTranslateLanguage = translateLanguages_.value (uiTranslateLanguage);
settings.setValue (settings_names::translationLanguage, settingsTranslateLanguage);
QString sourceLanguage = settings_values::sourceLanguage;
if (translateLanguages_.contains (uiOcrLanguage))
{
sourceLanguage = translateLanguages_.value (uiOcrLanguage);
}
QString trLanguage = dictionary_.translateUiToCode (ui->translateLangCombo->currentText ());
settings.setValue (settings_names::translationLanguage, trLanguage);
QString sourceLanguage = dictionary_.translateForOcrCode (ocrLanguage);
settings.setValue (settings_names::sourceLanguage, sourceLanguage);
settings.endGroup ();
}
@ -96,46 +86,30 @@ void SettingsEditor::openTessdataDialog()
void SettingsEditor::loadSettings()
{
#define GET(FIELD) settings.value (settings_names::FIELD, settings_values::FIELD)
QSettings settings;
settings.beginGroup (settings_names::guiGroup);
QString captureHotkey = settings.value (settings_names::captureHotkey,
settings_values::captureHotkey).toString ();
ui->captureEdit->setText (captureHotkey);
QString repeatHotkey = settings.value (settings_names::repeatHotkey,
settings_values::repeatHotkey).toString ();
ui->repeatEdit->setText (repeatHotkey);
QString clipboardHotkey = settings.value (settings_names::clipboardHotkey,
settings_values::clipboardHotkey).toString ();
ui->clipboardEdit->setText (clipboardHotkey);
int resultShowType = settings.value (settings_names::resultShowType,
settings_values::resultShowType).toInt ();
QAbstractButton* button = buttonGroup_->button (resultShowType);
ui->captureEdit->setText (GET(captureHotkey).toString ());
ui->repeatEdit->setText (GET(repeatHotkey).toString ());
ui->clipboardEdit->setText (GET(clipboardHotkey).toString ());
QAbstractButton* button = buttonGroup_->button (GET(resultShowType).toInt ());
Q_CHECK_PTR (button);
button->setChecked (true);
settings.endGroup ();
settings.beginGroup (settings_names::recogntionGroup);
QString tessDataPlace = settings.value (settings_names::tessDataPlace,
settings_values::tessDataPlace).toString ();
ui->tessdataEdit->setText (tessDataPlace);
QString settingsOcrLanguage = settings.value (settings_names::ocrLanguage,
settings_values::ocrLanguage).toString ();
QString uiOcrLanguage = ocrLanguages_.key (settingsOcrLanguage, settingsOcrLanguage);
ui->ocrLangCombo->setCurrentText (uiOcrLanguage);
int imageScale = settings.value (settings_names::imageScale,
settings_values::imageScale).toInt ();
ui->imageScaleSpin->setValue (imageScale);
ui->tessdataEdit->setText (GET(tessDataPlace).toString ());
QString ocrLanguage = dictionary_.ocrCodeToUi (GET(ocrLanguage).toString ());
ui->ocrLangCombo->setCurrentText (ocrLanguage);
ui->imageScaleSpin->setValue (GET(imageScale).toInt ());
settings.endGroup ();
settings.beginGroup (settings_names::translationGroup);
QString settingsTranslateLanguage = settings.value (settings_names::translationLanguage,
settings_values::translationLanguage).toString ();
QString uiTranslateLanguage = translateLanguages_.key (settingsTranslateLanguage);
Q_ASSERT (!uiTranslateLanguage.isEmpty ());
ui->translateLangCombo->setCurrentText (uiTranslateLanguage);
QString trLanguage = dictionary_.translateCodeToUi (GET(translationLanguage).toString ());
ui->translateLangCombo->setCurrentText (trLanguage);
settings.endGroup ();
#undef GET
}
void SettingsEditor::saveState() const
@ -155,148 +129,5 @@ void SettingsEditor::loadState()
void SettingsEditor::initOcrLangCombo()
{
ui->ocrLangCombo->clear ();
QString tessdataDir = ui->tessdataEdit->text ();
QDir dir (tessdataDir + "/tessdata/");
if (!dir.exists ())
{
return;
}
QStringList files = dir.entryList (QStringList () << "*.traineddata", QDir::Files);
QStringList languages;
foreach (const QString& file, files)
{
QString lang = file.left (file.indexOf ("."));
lang = ocrLanguages_.key (lang, lang); // Replace with readable text if can.
languages << lang;
}
ui->ocrLangCombo->addItems (languages);
}
void SettingsEditor::initTranslateLanguages()
{
translateLanguages_.insert(tr("Afrikaans"),"af");
translateLanguages_.insert(tr("Albanian"),"sq");
translateLanguages_.insert(tr("Arabic"),"ar");
translateLanguages_.insert(tr("Armenian"),"hy");
translateLanguages_.insert(tr("Azerbaijani"),"az");
translateLanguages_.insert(tr("Basque"),"eu");
translateLanguages_.insert(tr("Belarusian"),"be");
translateLanguages_.insert(tr("Bulgarian"),"bg");
translateLanguages_.insert(tr("Catalan"),"ca");
translateLanguages_.insert(tr("Chinese (Simplified)"),"zh-CN");
translateLanguages_.insert(tr("Chinese (Traditional)"),"zh-TW");
translateLanguages_.insert(tr("Croatian"),"hr");
translateLanguages_.insert(tr("Czech"),"cs");
translateLanguages_.insert(tr("Danish"),"da");
translateLanguages_.insert(tr("Dutch"),"nl");
translateLanguages_.insert(tr("English"),"en");
translateLanguages_.insert(tr("Estonian"),"et");
translateLanguages_.insert(tr("Filipino"),"tl");
translateLanguages_.insert(tr("Finnish"),"fi");
translateLanguages_.insert(tr("French"),"fr");
translateLanguages_.insert(tr("Galician"),"gl");
translateLanguages_.insert(tr("Georgian"),"ka");
translateLanguages_.insert(tr("German"),"de");
translateLanguages_.insert(tr("Greek"),"el");
translateLanguages_.insert(tr("Haitian Creole"),"ht");
translateLanguages_.insert(tr("Hebrew"),"iw");
translateLanguages_.insert(tr("Hindi"),"hi");
translateLanguages_.insert(tr("Hungarian"),"hu");
translateLanguages_.insert(tr("Icelandic"),"is");
translateLanguages_.insert(tr("Indonesian"),"id");
translateLanguages_.insert(tr("Irish"),"ga");
translateLanguages_.insert(tr("Italian"),"it");
translateLanguages_.insert(tr("Japanese"),"ja");
translateLanguages_.insert(tr("Korean"),"ko");
translateLanguages_.insert(tr("Latvian"),"lv");
translateLanguages_.insert(tr("Lithuanian"),"lt");
translateLanguages_.insert(tr("Macedonian"),"mk");
translateLanguages_.insert(tr("Malay"),"ms");
translateLanguages_.insert(tr("Maltese"),"mt");
translateLanguages_.insert(tr("Norwegian"),"no");
translateLanguages_.insert(tr("Persian"),"fa");
translateLanguages_.insert(tr("Polish"),"pl");
translateLanguages_.insert(tr("Portuguese"),"pt");
translateLanguages_.insert(tr("Romanian"),"ro");
translateLanguages_.insert(tr("Russian"),"ru");
translateLanguages_.insert(tr("Serbian"),"sr");
translateLanguages_.insert(tr("Slovak"),"sk");
translateLanguages_.insert(tr("Slovenian"),"sl");
translateLanguages_.insert(tr("Spanish"),"es");
translateLanguages_.insert(tr("Swahili"),"sw");
translateLanguages_.insert(tr("Swedish"),"sv");
translateLanguages_.insert(tr("Thai"),"th");
translateLanguages_.insert(tr("Turkish"),"tr");
translateLanguages_.insert(tr("Ukrainian"),"uk");
translateLanguages_.insert(tr("Urdu"),"ur");
translateLanguages_.insert(tr("Vietnamese"),"vi");
translateLanguages_.insert(tr("Welsh"),"cy");
translateLanguages_.insert(tr("Yiddish"),"yi");
}
void SettingsEditor::initOcrLanguages()
{
ocrLanguages_.insert(tr("Ancient Greek"),"grc");
ocrLanguages_.insert(tr("Esperanto alternative"),"epo_alt");
ocrLanguages_.insert(tr("English"),"eng");
ocrLanguages_.insert(tr("Ukrainian"),"ukr");
ocrLanguages_.insert(tr("Turkish"),"tur");
ocrLanguages_.insert(tr("Thai"),"tha");
ocrLanguages_.insert(tr("Tagalog"),"tgl");
ocrLanguages_.insert(tr("Telugu"),"tel");
ocrLanguages_.insert(tr("Tamil"),"tam");
ocrLanguages_.insert(tr("Swedish"),"swe");
ocrLanguages_.insert(tr("Swahili"),"swa");
ocrLanguages_.insert(tr("Serbian"),"srp");
ocrLanguages_.insert(tr("Albanian"),"sqi");
ocrLanguages_.insert(tr("Spanish"),"spa");
ocrLanguages_.insert(tr("Slovenian"),"slv");
ocrLanguages_.insert(tr("Slovakian"),"slk");
ocrLanguages_.insert(tr("Romanian"),"ron");
ocrLanguages_.insert(tr("Portuguese"),"por");
ocrLanguages_.insert(tr("Polish"),"pol");
ocrLanguages_.insert(tr("Norwegian"),"nor");
ocrLanguages_.insert(tr("Dutch"),"nld");
ocrLanguages_.insert(tr("Malay"),"msa");
ocrLanguages_.insert(tr("Maltese"),"mlt");
ocrLanguages_.insert(tr("Macedonian"),"mkd");
ocrLanguages_.insert(tr("Malayalam"),"mal");
ocrLanguages_.insert(tr("Lithuanian"),"lit");
ocrLanguages_.insert(tr("Latvian"),"lav");
ocrLanguages_.insert(tr("Korean"),"kor");
ocrLanguages_.insert(tr("Kannada"),"kan");
ocrLanguages_.insert(tr("Italian"),"ita");
ocrLanguages_.insert(tr("Icelandic"),"isl");
ocrLanguages_.insert(tr("Indonesian"),"ind");
ocrLanguages_.insert(tr("Cherokee"),"chr");
ocrLanguages_.insert(tr("Hungarian"),"hun");
ocrLanguages_.insert(tr("Croatian"),"hrv");
ocrLanguages_.insert(tr("Hindi"),"hin");
ocrLanguages_.insert(tr("Hebrew"),"heb");
ocrLanguages_.insert(tr("Galician"),"glg");
ocrLanguages_.insert(tr("Middle French (ca. 1400-1600)"),"frm");
ocrLanguages_.insert(tr("Frankish"),"frk");
ocrLanguages_.insert(tr("French"),"fra");
ocrLanguages_.insert(tr("Finnish"),"fin");
ocrLanguages_.insert(tr("Basque"),"eus");
ocrLanguages_.insert(tr("Estonian"),"est");
ocrLanguages_.insert(tr("Math / equation"),"equ");
ocrLanguages_.insert(tr("Esperanto"),"epo");
ocrLanguages_.insert(tr("Middle English (1100-1500)"),"enm");
ocrLanguages_.insert(tr("Greek"),"ell");
ocrLanguages_.insert(tr("German"),"deu");
ocrLanguages_.insert(tr("Danish"),"dan");
ocrLanguages_.insert(tr("Czech"),"ces");
ocrLanguages_.insert(tr("Catalan"),"cat");
ocrLanguages_.insert(tr("Bulgarian"),"bul");
ocrLanguages_.insert(tr("Bengali"),"ben");
ocrLanguages_.insert(tr("Belarusian"),"bel");
ocrLanguages_.insert(tr("Azerbaijani"),"aze");
ocrLanguages_.insert(tr("Arabic"),"ara");
ocrLanguages_.insert(tr("Afrikaans"),"afr");
ocrLanguages_.insert(tr("Japanese"),"jpn");
ocrLanguages_.insert(tr("Chinese (Simplified)"),"chi_sim");
ocrLanguages_.insert(tr("Chinese (Traditional)"),"chi_tra");
ocrLanguages_.insert(tr("Russian"),"rus");
ocrLanguages_.insert(tr("Vietnamese"),"vie");
ui->ocrLangCombo->addItems (dictionary_.availableOcrLanguagesUi ());
}

View File

@ -8,13 +8,14 @@
namespace Ui {
class SettingsEditor;
}
class LanguageHelper;
class SettingsEditor : public QDialog
{
Q_OBJECT
public:
explicit SettingsEditor(QWidget *parent = 0);
explicit SettingsEditor(const LanguageHelper& dictionary, QWidget *parent = 0);
~SettingsEditor();
signals:
@ -32,14 +33,11 @@ class SettingsEditor : public QDialog
void loadSettings ();
void saveState () const;
void loadState ();
void initTranslateLanguages ();
void initOcrLanguages ();
private:
Ui::SettingsEditor *ui;
const LanguageHelper& dictionary_;
QButtonGroup* buttonGroup_;
QMap<QString, QString> translateLanguages_;
QMap<QString, QString> ocrLanguages_;
};
#endif // SETTINGSEDITOR_H