From 85da4a3045a728c09af21c546ecd5d7534df164a Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Fri, 2 Feb 2018 20:57:27 +0100 Subject: [PATCH] Translation paths based on OS --- flameshot.pro | 6 ++++-- src/main.cpp | 13 +++++++++++-- src/utils/pathinfo.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/utils/pathinfo.h | 26 ++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/utils/pathinfo.cpp create mode 100644 src/utils/pathinfo.h diff --git a/flameshot.pro b/flameshot.pro index 9beb3afb..5e1dd459 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -120,7 +120,8 @@ SOURCES += src/main.cpp \ src/capture/workers/launcher/terminallauncher.cpp \ src/config/visualseditor.cpp \ src/config/extendedslider.cpp \ - src/capture/workers/launcher/openwithprogram.cpp + src/capture/workers/launcher/openwithprogram.cpp \ + src/utils/pathinfo.cpp HEADERS += src/capture/widgets/buttonhandler.h \ src/infowindow.h \ @@ -176,7 +177,8 @@ HEADERS += src/capture/widgets/buttonhandler.h \ src/capture/workers/launcher/terminallauncher.h \ src/config/visualseditor.h \ src/config/extendedslider.h \ - src/capture/workers/launcher/openwithprogram.h + src/capture/workers/launcher/openwithprogram.h \ + src/utils/pathinfo.h unix:!macx { SOURCES += src/core/flameshotdbusadapter.cpp \ diff --git a/src/main.cpp b/src/main.cpp index fca067fa..1aaab17a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ #include "src/utils/confighandler.h" #include "src/cli/commandlineparser.h" #include "src/utils/systemnotification.h" +#include "src/utils/pathinfo.h" #include #include #include @@ -41,8 +42,16 @@ int main(int argc, char *argv[]) { qApp->setApplicationVersion(static_cast(APP_VERSION)); QTranslator translator; - translator.load(QLocale::system().language(), - "Internationalization", "_", "/usr/share/flameshot/translations/"); + QStringList trPaths = PathInfo::translations(); + bool match = false; + for (const QString &path: trPaths) { + match = translator.load(QLocale::system().language(), + "Internationalization", "_", + path); + if (match) { + break; + } + } // no arguments, just launch Flameshot if (argc == 1) { diff --git a/src/utils/pathinfo.cpp b/src/utils/pathinfo.cpp new file mode 100644 index 00000000..a7d48f01 --- /dev/null +++ b/src/utils/pathinfo.cpp @@ -0,0 +1,36 @@ +// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Flameshot. If not, see . + +#include "pathinfo.h" +#include +#include +#include + +QStringList PathInfo::translations() { + QString binaryPath = QFileInfo(qApp->applicationFilePath()) + .absoluteFilePath(); + QString trPath = QDir::toNativeSeparators(binaryPath) + "translations"; +#if defined(Q_OS_LINUX) + return QStringList() + << trPath + << "/usr/share/flameshot/translations" + << "/usr/local/share/flameshot/translations"; +#elif defined(Q_OS_WIN) + return QStringList() + << trPath; +#endif +} diff --git a/src/utils/pathinfo.h b/src/utils/pathinfo.h new file mode 100644 index 00000000..eb27098d --- /dev/null +++ b/src/utils/pathinfo.h @@ -0,0 +1,26 @@ +// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Flameshot. If not, see . + +#pragma once + +#include + +class PathInfo +{ +public: + static QStringList translations(); +};