Skip to content

Commit

Permalink
Merge branch 'translations-deployment-mac-linux-fix' into translation…
Browse files Browse the repository at this point in the history
…s-deploy-ment-mac-linux-fix-deploy-test
  • Loading branch information
a1ext committed Jan 20, 2019
2 parents a1bdfa3 + 575dcbc commit 6450889
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 44 deletions.
71 changes: 32 additions & 39 deletions src/CutterApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,56 +237,49 @@ bool CutterApplication::loadTranslations()
const auto &allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
QLocale::AnyCountry);

bool cutterTrLoaded = false;

for (const QLocale &it : allLocales) {
const QString &langPrefix = it.bcp47Name();
if (langPrefix == language) {
QTranslator *t = new QTranslator;
QTranslator *qtBaseTranslator = new QTranslator;
QTranslator *qtTranslator = new QTranslator;

const QString &cutterTranslationPath = QCoreApplication::applicationDirPath() + QDir::separator()
+ QStringLiteral("translations");
const QString &translationsPath(QLibraryInfo::location(QLibraryInfo::TranslationsPath));

const QStringList &cutterTrPaths = {
cutterTranslationPath,
translationsPath,
#ifdef Q_OS_MAC
QStringLiteral("%1/../Resources/translations").arg(QCoreApplication::applicationDirPath()),
#endif // Q_OS_MAC
};

bool cutterTrLoaded = false;
for (const auto &trPath : cutterTrPaths) {
if (t->load(it, QLatin1String("cutter"), QLatin1String("_"), trPath)) {
installTranslator(t);
cutterTrLoaded = true;
break;
}
}
if (!cutterTrLoaded) {
qWarning() << "Cannot load Cutter's translation for " << language;
delete t;
}
QApplication::setLayoutDirection(it.textDirection());
QLocale::setDefault(it);

if (qtTranslator->load(it, "qt", "_", translationsPath)) {
installTranslator(qtTranslator);
}
else {
delete qtTranslator;
}
QTranslator *trCutter = new QTranslator;
QTranslator *trQtBase = new QTranslator;
QTranslator *trQt = new QTranslator;

if (qtBaseTranslator->load(it, "qtbase", "_", translationsPath)) {
installTranslator(qtBaseTranslator);
}
else {
delete qtBaseTranslator;
const QStringList &cutterTrPaths = Config()->getTranslationsDirectories();

for (const auto &trPath : cutterTrPaths) {
if (trCutter && trCutter->load(it, QLatin1String("cutter"), QLatin1String("_"), trPath)) {
installTranslator(trCutter);
cutterTrLoaded = true;
trCutter = nullptr;
}
if (trQt && trQt->load(it, "qt", "_", trPath)) {
installTranslator(trQt);
trQt = nullptr;
}

if (trQtBase && trQtBase->load(it, "qtbase", "_", trPath)) {
installTranslator(trQtBase);
trQtBase = nullptr;
}
}

if (trCutter)
delete trCutter;
if (trQt)
delete trQt;
if (trQtBase)
delete trQtBase;

return true;
}
}
if (!cutterTrLoaded) {
qWarning() << "Cannot load Cutter's translation for " << language;
}
return false;
}
36 changes: 31 additions & 5 deletions src/common/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QFontDatabase>
#include <QFile>
#include <QApplication>
#include <QLibraryInfo>

#include "common/ColorSchemeFileSaver.h"

Expand Down Expand Up @@ -462,10 +463,21 @@ void Configuration::setConfig(const QString &key, const QVariant &value)
*/
QStringList Configuration::getAvailableTranslations()
{
QDir dir(QCoreApplication::applicationDirPath() + QDir::separator() +
"translations");
QStringList fileNames = dir.entryList(QStringList("cutter_*.qm"), QDir::Files,
QDir::Name);
const auto &trDirs = getTranslationsDirectories();

QSet<QString> fileNamesSet;
for (const auto &trDir : trDirs) {
QDir dir(trDir);
if (!dir.exists())
continue;
const QStringList &currTrFileNames = dir.entryList(QStringList("cutter_*.qm"), QDir::Files,
QDir::Name);
for (const auto &trFile : currTrFileNames)
fileNamesSet << trFile;
}

QStringList fileNames = fileNamesSet.toList();
qSort(fileNames);
QStringList languages;
QString currLanguageName;
auto allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
Expand All @@ -483,7 +495,7 @@ QStringList Configuration::getAvailableTranslations()
}
}
}
return languages << "English";
return languages << QLatin1String("English");
}

/*!
Expand All @@ -500,3 +512,17 @@ bool Configuration::isFirstExecution()
return true;
}
}

QStringList Configuration::getTranslationsDirectories() const
{
static const QString cutterTranslationPath = QCoreApplication::applicationDirPath() + QDir::separator()
+ QLatin1String("translations");

return {
cutterTranslationPath,
QLibraryInfo::location(QLibraryInfo::TranslationsPath),
#ifdef Q_OS_MAC
QStringLiteral("%1/../Resources/translations").arg(QCoreApplication::applicationDirPath()),
#endif // Q_OS_MAC
};
}
1 change: 1 addition & 0 deletions src/common/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class Configuration : public QObject
void setConfig(const QString &key, const QVariant &value);
bool isFirstExecution();

QStringList getTranslationsDirectories() const;

signals:
void fontsUpdated();
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/WelcomeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ WelcomeDialog::WelcomeDialog(QWidget *parent) :
ui(new Ui::WelcomeDialog)
{
ui->setupUi(this);
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
ui->logoSvgWidget->load(Config()->getLogoFile());
ui->versionLabel->setText("<font color='#a4a9b2'>" + tr("Version ") + CUTTER_VERSION_FULL + "</font>");
ui->themeComboBox->setCurrentIndex(Config()->getTheme());
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/preferences/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
setWindowFlag(Qt::WindowContextHelpButtonHint, false);

QList<PreferenceCategory> prefs {

Expand Down

0 comments on commit 6450889

Please sign in to comment.