Added translations for oracle; fix #293

Translations have been updated.
This commit is contained in:
Fabio Bas 2015-02-08 21:17:51 +01:00
parent 25747a0964
commit f80e319900
23 changed files with 11395 additions and 8800 deletions

View file

@ -1,11 +1,33 @@
#include <QApplication>
#include <QTextCodec>
#include <QIcon>
#include <QTranslator>
#include <QLibraryInfo>
#include "main.h"
#include "oraclewizard.h"
#include "settingscache.h"
QTranslator *translator, *qtTranslator;
SettingsCache *settingsCache;
const QString translationPrefix = "oracle";
#ifdef TRANSLATION_PATH
QString translationPath = TRANSLATION_PATH;
#else
QString translationPath = QString();
#endif
void installNewTranslator()
{
QString lang = settingsCache->getLang();
qtTranslator->load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
qApp->installTranslator(qtTranslator);
translator->load(translationPrefix + "_" + lang, translationPath);
qApp->installTranslator(translator);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
@ -20,8 +42,20 @@ int main(int argc, char *argv[])
// this can't be changed, as it influences the default savepath for cards.xml
QCoreApplication::setApplicationName("Cockatrice");
if (translationPath.isEmpty()) {
#ifdef Q_OS_MAC
translationPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
#elif defined(Q_OS_WIN)
translationPath = app.applicationDirPath() + "/translations";
#endif
}
settingsCache = new SettingsCache;
qtTranslator = new QTranslator;
translator = new QTranslator;
installNewTranslator();
OracleWizard wizard;
QIcon icon(":/resources/appicon.svg");

12
oracle/src/main.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef MAIN_H
#define MAIN_H
class QTranslator;
extern QTranslator *translator;
extern const QString translationPrefix;
extern QString translationPath;
void installNewTranslator();
#endif

View file

@ -12,6 +12,7 @@
#include <QFileDialog>
#include <QGridLayout>
#include <QLabel>
#include <QComboBox>
#include <QLineEdit>
#include <QMessageBox>
#include <QNetworkAccessManager>
@ -25,6 +26,8 @@
#include "oraclewizard.h"
#include "oracleimporter.h"
#include "main.h"
#include "settingscache.h"
#ifdef HAS_ZLIB
#include "zip/unzip.h"
@ -40,6 +43,7 @@ OracleWizard::OracleWizard(QWidget *parent)
: QWizard(parent)
{
settings = new QSettings(this);
connect(settingsCache, SIGNAL(langChanged()), this, SLOT(updateLanguage()));
importer = new OracleImporter(
#if QT_VERSION < 0x050000
@ -54,8 +58,29 @@ OracleWizard::OracleWizard(QWidget *parent)
addPage(new ChooseSetsPage);
addPage(new SaveSetsPage);
retranslateUi();
}
void OracleWizard::updateLanguage()
{
qApp->removeTranslator(translator);
installNewTranslator();
}
void OracleWizard::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
QDialog::changeEvent(event);
}
void OracleWizard::retranslateUi()
{
setWindowTitle(tr("Oracle Importer"));
QWizard::setButtonText(QWizard::FinishButton, tr("Save"));
for (int i = 0; i < pageIds().count(); i++)
dynamic_cast<OracleWizardPage *>(page(i))->retranslateUi();
}
void OracleWizard::accept()
@ -78,31 +103,66 @@ void OracleWizard::disableButtons()
IntroPage::IntroPage(QWidget *parent)
: OracleWizardPage(parent)
{
setTitle(tr("Introduction"));
label = new QLabel(tr("This wizard will import the list of sets and cards "
"that will be used by Cockatrice. You will need to "
"specify an url or a filename that will be used as a "
"source, and then choose the wanted sets from the list "
"of the available ones."),
this);
label = new QLabel(this);
label->setWordWrap(true);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(label);
languageLabel = new QLabel(this);
languageBox = new QComboBox(this);
QString setLanguage = settingsCache->getLang();
QStringList qmFiles = findQmFiles();
for (int i = 0; i < qmFiles.size(); i++) {
QString langName = languageName(qmFiles[i]);
languageBox->addItem(langName, qmFiles[i]);
if ((qmFiles[i] == setLanguage) || (setLanguage.isEmpty() && langName == tr("English")))
languageBox->setCurrentIndex(i);
}
connect(languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int)));
QGridLayout *layout = new QGridLayout(this);
layout->addWidget(label, 0, 0, 1, 2);
layout->addWidget(languageLabel, 1, 0);
layout->addWidget(languageBox, 1, 1);
setLayout(layout);
}
QStringList IntroPage::findQmFiles()
{
QDir dir(translationPath);
QStringList fileNames = dir.entryList(QStringList(translationPrefix + "_*.qm"), QDir::Files, QDir::Name);
fileNames.replaceInStrings(QRegExp(translationPrefix + "_(.*)\\.qm"), "\\1");
return fileNames;
}
QString IntroPage::languageName(const QString &qmFile)
{
QTranslator translator;
translator.load(translationPrefix + "_" + qmFile + ".qm", translationPath);
return translator.translate("IntroPage", "English");
}
void IntroPage::languageBoxChanged(int index)
{
settingsCache->setLang(languageBox->itemData(index).toString());
}
void IntroPage::retranslateUi()
{
setTitle(tr("Introduction"));
label->setText(tr("This wizard will import the list of sets and cards "
"that will be used by Cockatrice.<br/>You will need to "
"specify an url or a filename that will be used as a "
"source, and then choose the wanted sets from the list "
"of the available ones."));
languageLabel->setText(tr("Language:"));
}
LoadSetsPage::LoadSetsPage(QWidget *parent)
: OracleWizardPage(parent), nam(0)
{
setTitle(tr("Source selection"));
setSubTitle(tr("Please specify a source for the list of sets and cards. "
"You can specify an url address that will be download or "
"use an existing file from your computer."));
urlRadioButton = new QRadioButton(tr("Download url:"), this);
fileRadioButton = new QRadioButton(tr("Local file:"), this);
urlRadioButton = new QRadioButton(this);
fileRadioButton = new QRadioButton(this);
urlLineEdit = new QLineEdit(this);
fileLineEdit = new QLineEdit(this);
@ -112,10 +172,10 @@ LoadSetsPage::LoadSetsPage(QWidget *parent)
urlRadioButton->setChecked(true);
urlButton = new QPushButton(tr("Restore default url"), this);
urlButton = new QPushButton(this);
connect(urlButton, SIGNAL(clicked()), this, SLOT(actRestoreDefaultUrl()));
fileButton = new QPushButton(tr("Choose file..."), this);
fileButton = new QPushButton(this);
connect(fileButton, SIGNAL(clicked()), this, SLOT(actLoadSetsFile()));
QGridLayout *layout = new QGridLayout(this);
@ -141,6 +201,19 @@ void LoadSetsPage::initializePage()
progressBar->hide();
}
void LoadSetsPage::retranslateUi()
{
setTitle(tr("Source selection"));
setSubTitle(tr("Please specify a source for the list of sets and cards. "
"You can specify an url address that will be download or "
"use an existing file from your computer."));
urlRadioButton->setText(tr("Download url:"));
fileRadioButton->setText(tr("Local file:"));
urlButton->setText(tr("Restore default url"));
fileButton->setText(tr("Choose file..."));
}
void LoadSetsPage::actRestoreDefaultUrl()
{
urlLineEdit->setText(ALLSETS_URL);
@ -356,11 +429,6 @@ void LoadSetsPage::importFinished()
ChooseSetsPage::ChooseSetsPage(QWidget *parent)
: OracleWizardPage(parent)
{
setTitle(tr("Sets selection"));
setSubTitle(tr("The following sets has been found in the source file. "
"Please mark the sets that will be imported.\n"
"All core and expansion sets are selected by default."));
checkBoxLayout = new QVBoxLayout;
QWidget *checkboxFrame = new QWidget(this);
@ -370,9 +438,9 @@ ChooseSetsPage::ChooseSetsPage(QWidget *parent)
checkboxArea->setWidget(checkboxFrame);
checkboxArea->setWidgetResizable(true);
checkAllButton = new QPushButton(tr("&Check all"));
checkAllButton = new QPushButton(this);
connect(checkAllButton, SIGNAL(clicked()), this, SLOT(actCheckAll()));
uncheckAllButton = new QPushButton(tr("&Uncheck all"));
uncheckAllButton = new QPushButton(this);
connect(uncheckAllButton, SIGNAL(clicked()), this, SLOT(actUncheckAll()));
QGridLayout *layout = new QGridLayout(this);
@ -400,6 +468,17 @@ void ChooseSetsPage::initializePage()
}
}
void ChooseSetsPage::retranslateUi()
{
setTitle(tr("Sets selection"));
setSubTitle(tr("The following sets has been found in the source file. "
"Please mark the sets that will be imported.\n"
"All core and expansion sets are selected by default."));
checkAllButton->setText(tr("&Check all"));
uncheckAllButton->setText(tr("&Uncheck all"));
}
void ChooseSetsPage::checkBoxChanged(int state)
{
QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
@ -438,12 +517,7 @@ bool ChooseSetsPage::validatePage()
SaveSetsPage::SaveSetsPage(QWidget *parent)
: OracleWizardPage(parent)
{
setTitle(tr("Sets imported"));
setSubTitle(tr("The following sets has been imported. "
"Press \"Save\" to save the imported cards to the Cockatrice database."));
defaultPathCheckBox = new QCheckBox(this);
defaultPathCheckBox->setText(tr("Save to the default path (recommended)"));
defaultPathCheckBox->setChecked(true);
messageLog = new QTextEdit(this);
@ -471,6 +545,15 @@ void SaveSetsPage::initializePage()
QMessageBox::critical(this, tr("Error"), tr("No set has been imported."));
}
void SaveSetsPage::retranslateUi()
{
setTitle(tr("Sets imported"));
setSubTitle(tr("The following sets has been imported. "
"Press \"Save\" to save the imported cards to the Cockatrice database."));
defaultPathCheckBox->setText(tr("Save to the default path (recommended)"));
}
void SaveSetsPage::updateTotalProgress(int cardsImported, int /* setIndex */, const QString &setName)
{
if (setName.isEmpty()) {

View file

@ -7,6 +7,7 @@
class QCheckBox;
class QGroupBox;
class QComboBox;
class QLabel;
class QLineEdit;
class QRadioButton;
@ -25,9 +26,17 @@ public:
void accept();
void enableButtons();
void disableButtons();
void retranslateUi();
public:
OracleImporter *importer;
QSettings * settings;
private slots:
void updateLanguage();
private:
QStringList findQmFiles();
QString languageName(const QString &qmFile);
protected:
void changeEvent(QEvent *event);
};
@ -36,6 +45,7 @@ class OracleWizardPage : public QWizardPage
Q_OBJECT
public:
OracleWizardPage(QWidget *parent = 0): QWizardPage(parent) {};
virtual void retranslateUi() = 0;
protected:
inline OracleWizard *wizard() { return (OracleWizard*) QWizardPage::wizard(); };
};
@ -44,9 +54,16 @@ class IntroPage : public OracleWizardPage
{
Q_OBJECT
public:
IntroPage(QWidget *parent = 0);
IntroPage(QWidget *parent = 0);
void retranslateUi();
private:
QLabel *label;
QStringList findQmFiles();
QString languageName(const QString &qmFile);
private:
QLabel *label, *languageLabel;
QComboBox *languageBox;
private slots:
void languageBoxChanged(int index);
};
class LoadSetsPage : public OracleWizardPage
@ -54,6 +71,7 @@ class LoadSetsPage : public OracleWizardPage
Q_OBJECT
public:
LoadSetsPage(QWidget *parent = 0);
void retranslateUi();
protected:
void initializePage();
bool validatePage();
@ -85,6 +103,7 @@ class ChooseSetsPage : public OracleWizardPage
Q_OBJECT
public:
ChooseSetsPage(QWidget *parent = 0);
void retranslateUi();
protected:
void initializePage();
bool validatePage();
@ -103,6 +122,7 @@ class SaveSetsPage : public OracleWizardPage
Q_OBJECT
public:
SaveSetsPage(QWidget *parent = 0);
void retranslateUi();
private:
QTextEdit *messageLog;
QCheckBox * defaultPathCheckBox;