diff --git a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp index 17588fc97..0d8a958fe 100644 --- a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp @@ -40,6 +40,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- TapeConfigurationPage::TapeConfigurationPage(QWidget *parent) @@ -147,8 +148,14 @@ QGroupBox *TapeConfigurationPage::LangGroup() guiLabel = new QLabel(tr("GUI language")); langCombo = new QComboBox; - QDir dir(qApp->translationsPath()); - const QStringList fileNames = dir.entryList(QStringList("valentina_*.qm")); + QStringList fileNames; + QDirIterator it(qApp->translationsPath(), QStringList() << QStringList("valentina_*.qm"), QDir::Files, + QDirIterator::Subdirectories); + while (it.hasNext()) + { + it.next(); + fileNames.append(it.fileName()); + } for (int i = 0; i < fileNames.size(); ++i) { diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index a4c4c68b5..0649aff8f 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -397,10 +397,14 @@ VTapeSettings *MApplication::TapeSettings() } //--------------------------------------------------------------------------------------------------------------------- -QString MApplication::translationsPath() const +/** + * @brief translationsPath This function is implementation of the method VAbstractApplication::translationsPath. + */ +QString MApplication::translationsPath(const QString &locale) const { const QString trPath = QStringLiteral("/translations"); #ifdef Q_OS_WIN + Q_UNUSED(locale) QDir dir(QApplication::applicationDirPath() + trPath); if (dir.exists()) { @@ -411,7 +415,17 @@ QString MApplication::translationsPath() const return QApplication::applicationDirPath() + "/../../valentina/bin" + trPath; } #elif defined(Q_OS_MAC) - QDir dirBundle(QApplication::applicationDirPath() + QStringLiteral("/../Resources") + trPath); + QString mainPath; + if (locale.isEmpty()) + { + mainPath = QApplication::applicationDirPath() + QLatin1Literal("/../Resources") + trPath; + } + else + { + mainPath = QApplication::applicationDirPath() + QLatin1Literal("/../Resources") + trPath + QLatin1Literal("/") + + locale + QLatin1Literal(".lproj"); + } + QDir dirBundle(mainPath); if (dirBundle.exists()) { return dirBundle.absolutePath(); @@ -429,13 +443,14 @@ QString MApplication::translationsPath() const } } #else // Unix + Q_UNUSED(locale) QDir dir1(QApplication::applicationDirPath() + trPath); if (dir1.exists()) { return dir1.absolutePath(); } - QDir dir2(QApplication::applicationDirPath() + "/../../valentina/bin" + trPath); + QDir dir2(QApplication::applicationDirPath() + QLatin1Literal("/../../valentina/bin") + trPath); if (dir2.exists()) { return dir2.absolutePath(); diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h index 39594ef58..c7517b37c 100644 --- a/src/app/tape/mapplication.h +++ b/src/app/tape/mapplication.h @@ -71,7 +71,7 @@ public: virtual void OpenSettings() Q_DECL_OVERRIDE; VTapeSettings *TapeSettings(); - virtual QString translationsPath() const Q_DECL_OVERRIDE; + virtual QString translationsPath(const QString &locale = QString()) const Q_DECL_OVERRIDE; QString diagramsPath() const; void ShowDataBase(); diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 7735ff1ab..0e63fe33f 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -364,13 +364,27 @@ bool VApplication::notify(QObject *receiver, QEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -QString VApplication::translationsPath() const +/** + * @brief translationsPath This function is implementation of the method VAbstractApplication::translationsPath. + */ +QString VApplication::translationsPath(const QString &locale) const { const QString trPath = QStringLiteral("/translations"); #ifdef Q_OS_WIN + Q_UNUSED(locale) return QApplication::applicationDirPath() + trPath; #elif defined(Q_OS_MAC) - QDir dirBundle(QApplication::applicationDirPath() + QStringLiteral("/../Resources") + trPath); + QString mainPath; + if (locale.isEmpty()) + { + mainPath = QApplication::applicationDirPath() + QLatin1Literal("/../Resources") + trPath; + } + else + { + mainPath = QApplication::applicationDirPath() + QLatin1Literal("/../Resources") + trPath + QLatin1Literal("/") + + locale + QLatin1Literal(".lproj"); + } + QDir dirBundle(mainPath); if (dirBundle.exists()) { return dirBundle.absolutePath(); @@ -388,6 +402,7 @@ QString VApplication::translationsPath() const } } #else // Unix + Q_UNUSED(locale) QDir dir(QApplication::applicationDirPath() + trPath); if (dir.exists()) { diff --git a/src/app/valentina/core/vapplication.h b/src/app/valentina/core/vapplication.h index 60b14d573..8c0b1e5ed 100644 --- a/src/app/valentina/core/vapplication.h +++ b/src/app/valentina/core/vapplication.h @@ -61,7 +61,7 @@ public: void InitOptions(); - virtual QString translationsPath() const Q_DECL_OVERRIDE; + virtual QString translationsPath(const QString &locale = QString()) const Q_DECL_OVERRIDE; QString TapeFilePath() const; QTimer *getAutoSaveTimer() const; diff --git a/src/app/valentina/dialogs/configpages/configurationpage.cpp b/src/app/valentina/dialogs/configpages/configurationpage.cpp index 0e57b1351..1cbaef267 100644 --- a/src/app/valentina/dialogs/configpages/configurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/configurationpage.cpp @@ -41,6 +41,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- ConfigurationPage::ConfigurationPage(QWidget *parent) @@ -155,8 +156,14 @@ QGroupBox *ConfigurationPage::LangGroup() QLabel *guiLabel = new QLabel(tr("GUI language")); langCombo = new QComboBox; - QDir dir(qApp->translationsPath()); - const QStringList fileNames = dir.entryList(QStringList("valentina_*.qm")); + QStringList fileNames; + QDirIterator it(qApp->translationsPath(), QStringList() << QStringList("valentina_*.qm"), QDir::Files, + QDirIterator::Subdirectories); + while (it.hasNext()) + { + it.next(); + fileNames.append(it.fileName()); + } for (int i = 0; i < fileNames.size(); ++i) { diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index 300319907..82a6a564e 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -218,29 +218,29 @@ void VAbstractApplication::LoadTranslation(const QString &locale) ClearTranslation(); qtTranslator = new QTranslator(this); -#if defined(Q_OS_WIN) - qtTranslator->load("qt_" + locale, translationsPath()); +#if defined(Q_OS_WIN) || defined(Q_OS_MAC) + qtTranslator->load("qt_" + locale, translationsPath(locale)); #else qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); #endif installTranslator(qtTranslator); qtxmlTranslator = new QTranslator(this); -#if defined(Q_OS_WIN) - qtxmlTranslator->load("qtxmlpatterns_" + locale, translationsPath()); +#if defined(Q_OS_WIN) || defined(Q_OS_MAC) + qtxmlTranslator->load("qtxmlpatterns_" + locale, translationsPath(locale)); #else qtxmlTranslator->load("qtxmlpatterns_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); #endif installTranslator(qtxmlTranslator); appTranslator = new QTranslator(this); - appTranslator->load("valentina_" + locale, translationsPath()); + appTranslator->load("valentina_" + locale, translationsPath(locale)); installTranslator(appTranslator); const QString system = Settings()->GetPMSystemCode(); pmsTranslator = new QTranslator(this); - pmsTranslator->load("measurements_" + system + "_" + locale, translationsPath()); + pmsTranslator->load("measurements_" + system + "_" + locale, translationsPath(locale)); installTranslator(pmsTranslator); InitTrVars();//Very important do it after load QM files. diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index a02916d4c..e6c0aa3fc 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -56,7 +56,13 @@ public: virtual ~VAbstractApplication() Q_DECL_OVERRIDE; virtual const VTranslateVars *TrVars()=0; - virtual QString translationsPath() const=0; + /** + * @brief translationsPath return path to the root directory that contain QM files. + * @param locale used only in Mac OS. If empty return path to the root directory. If not - return path to locale + * subdirectory inside an app bundle. + * @return path to a directory that contain QM files. + */ + virtual QString translationsPath(const QString &locale = QString()) const=0; void LoadTranslation(const QString &locale);