-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtranslatedialog.cpp
50 lines (49 loc) · 1.55 KB
/
gtranslatedialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "gtranslatedialog.h"
#include "ui_gtranslatedialog.h"
#include "gtranslator.h"
#include "ui_viewer_mainwin.h"
#include <QLocale>
#include <QDebug>
#include <QMessageBox>
#include <QFile>
#include <QTextStream>
GTranslateDialog::GTranslateDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::GTranslateDialog)
{
ui->setupUi(this);
QString locale=QLocale::system().name();
QFile langfile(":/resources/lang.list");
if(!langfile.open(QIODevice::ReadOnly | QFile::Text)){
QMessageBox::information(this,tr("Can't read resource file"),tr("Error message: %1").arg(langfile.errorString()));
}else{
QTextStream str(&langfile);
QString list;
ui->sourceLangCombo->addItem(tr("Auto detect"),"");
while(!str.atEnd()){
list = str.readLine().trimmed();
qDebug() << list;
QStringList data = list.split("=");
ui->sourceLangCombo->addItem(data[0],data[1]);
ui->comboBox->addItem(data[0],data[1]);
qDebug() << data[0] << "," << data[1];
}
langfile.close();
}
}
GTranslateDialog::~GTranslateDialog()
{
delete ui;
}
void GTranslateDialog::setText(const QString& tmptext){
text = tmptext;
return;
}
void GTranslateDialog::showEvent(QShowEvent *){
ui->translatedText->setPlainText(text);
}
void GTranslateDialog::startTranslate(){
GTranslator translator(ui->comboBox->currentData().toString(),ui->sourceLangCombo->currentData().toString(),text,this);
QString translated = translator.translate();
ui->translatedText->setPlainText(translated);
}