Added translations (#848)

This commit is contained in:
optizone8 2018-10-31 16:07:53 +00:00 committed by xarkes
parent ec254b1d24
commit dd4a566408
9 changed files with 167 additions and 5 deletions

View File

@ -15,6 +15,14 @@ SET "BUILDDIR=build_%PLATFORM%"
ECHO Preparing directory
RMDIR /S /Q %BUILDDIR%
MKDIR %BUILDDIR%
ECHO Prepare translations
lrelease.exe ..\src\cutter.pro
RMDIR /S /Q %BUILDDIR%\translations
MKDIR %BUILDDIR%\translations
FOR %%i in (src\translations\*.qm) DO MOVE "%%~fi" "%CD%\%BUILDDIR%\translations"
CD %BUILDDIR%
ECHO Building cutter

View File

@ -9,8 +9,12 @@ ERR=0
#### User variables ####
BUILD="build"
QMAKE_CONF=""
ROOT_DIR=`pwd`
#QMAKE_CONF="CUTTER_ENABLE_JUPYTER=false CUTTER_ENABLE_QTWEBENGINE=false"
# Create translations
lrelease ./src/Cutter.pro
# Checking for radare2
r2 -v >/dev/null 2>&1
if [ $? = 0 ]; then
@ -56,6 +60,13 @@ cd "$BUILD" || exit 1
"$qmakepath" "$QMAKE_CONF" ../src/Cutter.pro
make -j4
ERR=$((ERR+$?))
# Move translations
mkdir "`pwd`/translations"
find "$ROOT_DIR/src/translations" -maxdepth 1 -type f | grep "cutter_..\.qm" | while read SRC_FILE; do
mv $SRC_FILE "`pwd`/translations"
done
cd ..
# Done

View File

@ -11,6 +11,13 @@ VERSION = $${CUTTER_VERSION_MAJOR}.$${CUTTER_VERSION_MINOR}.$${CUTTER_VERSION_PA
# Required QT version
lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5")
TRANSLATIONS += translations/cutter_de.ts \
translations/cutter_es.ts \
translations/cutter_fr.ts \
translations/cutter_it.ts \
translations/cutter_nl.ts \
translations/cutter_ru.ts
# Icon for OS X
ICON = img/cutter.icns

View File

@ -10,6 +10,8 @@
#include <QProcess>
#include <QPluginLoader>
#include <QDir>
#include <QTranslator>
#include <QLibraryInfo>
#ifdef CUTTER_ENABLE_JUPYTER
#include "common/JupyterConnection.h"
@ -22,6 +24,43 @@
CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc, argv)
{
QTranslator *t = new QTranslator;
QTranslator *qtBaseTranslator = new QTranslator;
QTranslator *qtTranslator = new QTranslator;
QString language = Config()->getCurrLocale().bcp47Name();
auto allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
QLocale::AnyCountry);
QString langPrefix;
if (language != "en") {
for (auto &it : allLocales) {
langPrefix = it.bcp47Name();
if (langPrefix == language) {
t->load(QString(QCoreApplication::applicationDirPath() + QDir::separator() +
"translations" + QDir::separator() +
"cutter_%1.qm").arg(langPrefix));
installTranslator(t);
QApplication::setLayoutDirection(it.textDirection());
QLocale::setDefault(it);
QString translationsPath(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
if (qtTranslator->load(it, "qt", "_", translationsPath)) {
installTranslator(qtTranslator);
} else {
delete qtTranslator;
}
if (qtBaseTranslator->load(it, "qtbase", "_", translationsPath)) {
installTranslator(qtBaseTranslator);
} else {
delete qtBaseTranslator;
}
break;
}
}
}
setOrganizationName("Cutter");
setApplicationName("Cutter");
setApplicationVersion(CUTTER_VERSION_FULL);

View File

@ -109,6 +109,16 @@ void Configuration::resetAll()
emit fontsUpdated();
}
QLocale Configuration::getCurrLocale() const
{
return s.value("locale", QLocale().system()).toLocale();
}
void Configuration::setLocale(const QLocale &l)
{
s.setValue("locale", l);
}
void Configuration::loadDefaultTheme()
{
/* Load Qt Theme */

View File

@ -36,6 +36,10 @@ public:
void resetAll();
// Languages
QLocale getCurrLocale() const;
void setLocale(const QLocale &l);
// Fonts
const QFont getFont() const;
void setFont(const QFont &font);

View File

@ -1,6 +1,7 @@
#include <QDir>
#include <QLabel>
#include <QFontDialog>
#include <QTranslator>
#include <QInputDialog>
#include <QComboBox>
@ -14,6 +15,34 @@
#include "common/ColorSchemeFileSaver.h"
#include "widgets/ColorSchemePrefWidget.h"
QStringList findLanguages()
{
QDir dir(QCoreApplication::applicationDirPath() + QDir::separator() +
"translations");
QStringList fileNames = dir.entryList(QStringList("cutter_*.qm"), QDir::Files,
QDir::Name);
QStringList languages;
QString currLanguageName;
auto allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
QLocale::AnyCountry);
for (auto i : fileNames) {
QString localeName = i.mid(sizeof("cutter_") - 1, 2);
for (auto j : allLocales) {
if (j.name().startsWith(localeName)) {
currLanguageName = j.nativeLanguageName();
currLanguageName = currLanguageName.at(0).toUpper() +
currLanguageName.right(currLanguageName.length() - 1);
languages << currLanguageName;
break;
}
}
}
return languages << "English";
}
AppearanceOptionsWidget::AppearanceOptionsWidget(PreferencesDialog *dialog, QWidget *parent)
: QDialog(parent),
ui(new Ui::AppearanceOptionsWidget)
@ -24,7 +53,22 @@ AppearanceOptionsWidget::AppearanceOptionsWidget(PreferencesDialog *dialog, QWid
updateFontFromConfig();
updateThemeFromConfig();
connect(Config(), &Configuration::fontsUpdated, this, &AppearanceOptionsWidget::updateFontFromConfig);
QStringList langs = findLanguages();
ui->languageComboBox->addItems(langs);
QString curr = Config()->getCurrLocale().nativeLanguageName();
curr = curr.at(0).toUpper() + curr.right(curr.length() - 1);
if (!langs.contains(curr)) {
curr = "English";
}
ui->languageComboBox->setCurrentText(curr);
connect(ui->languageComboBox,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this,
&AppearanceOptionsWidget::onLanguageComboBoxCurrentIndexChanged);
connect(Config(), &Configuration::fontsUpdated, this,
&AppearanceOptionsWidget::updateFontFromConfig);
connect(ui.get()->colorComboBox, &QComboBox::currentTextChanged, [&](const QString & name) {
static_cast<ColorSchemePrefWidget *>(ui.get()->colorSchemePrefWidget)->setNewScheme(name);
});
@ -114,3 +158,24 @@ void AppearanceOptionsWidget::on_deleteButton_clicked()
{
ColorSchemeFileWorker().deleteScheme(Config()->getCurrentTheme());
}
void AppearanceOptionsWidget::onLanguageComboBoxCurrentIndexChanged(int index)
{
QString language = ui->languageComboBox->itemText(index).toLower();
auto allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
QLocale::AnyCountry);
for (auto &it : allLocales) {
if (it.nativeLanguageName().toLower() == language) {
Config()->setLocale(it);
break;
}
}
QMessageBox mb;
mb.setWindowTitle(tr("Language settings"));
mb.setText(tr("Language will be changed after next application start."));
mb.setIcon(QMessageBox::Information);
mb.setStandardButtons(QMessageBox::Ok);
mb.exec();
}

View File

@ -34,6 +34,7 @@ private slots:
void on_colorComboBox_currentIndexChanged(int index);
void on_copyButton_clicked();
void on_deleteButton_clicked();
void onLanguageComboBoxCurrentIndexChanged(int index);
};

View File

@ -56,14 +56,14 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="themeLabel">
<property name="text">
<string>Qt Theme:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="themeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
@ -83,14 +83,14 @@
</item>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="colorLabel">
<property name="text">
<string>Color Theme</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="colorComboBox">
@ -137,6 +137,23 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="languageLabel">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="languageComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>