diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2020-06-22 19:38:36 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2020-07-15 21:37:50 +0000 |
commit | e95a95cdfeffb63ea73acd63c7f5b1743df76ed0 (patch) | |
tree | c41d9dbcb03764147b5ea1533463737b5c6a2e34 /src/plugins/projectexplorer | |
parent | 1cb1298a6d336810cfda86c97b4a785e37466dbb (diff) |
projectexplorer: add availableQmlPreviewTranslations()
Preparation for a test translations feature.
Change-Id: I1a7ccecab803f5838cd765b7dca99bcf5bb9e8a1
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/plugins/projectexplorer')
-rw-r--r-- | src/plugins/projectexplorer/project.cpp | 15 | ||||
-rw-r--r-- | src/plugins/projectexplorer/project.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index e7e6599ed9..254ac123bf 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -983,6 +983,21 @@ QVariant Project::extraData(const QString &key) const return d->m_extraData.value(key); } +QStringList Project::availableQmlPreviewTranslations(QString *errorMessage) +{ + const auto projectDirectory = rootProjectDirectory().toFileInfo().absoluteFilePath(); + const QDir languageDirectory(projectDirectory + "/i18n"); + const auto qmFiles = languageDirectory.entryList({"qml_*.qm"}); + if (qmFiles.isEmpty() && errorMessage) + errorMessage->append(tr("Could not find any qml_*.qm file at '%1'").arg(languageDirectory.absolutePath())); + return Utils::transform(qmFiles, [](const QString &qmFile) { + const int localeStartPosition = qmFile.lastIndexOf("_") + 1; + const int localeEndPosition = qmFile.size() - QString(".qm").size(); + const QString locale = qmFile.left(localeEndPosition).mid(localeStartPosition); + return locale; + }); +} + #if defined(WITH_TESTS) } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index b6b65e6889..58d6a914b8 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -173,6 +173,8 @@ public: void setExtraData(const QString &key, const QVariant &data); QVariant extraData(const QString &key) const; + QStringList availableQmlPreviewTranslations(QString *errorMessage); + signals: void projectFileIsDirty(const Utils::FilePath &path); |