From b1fc2cdbb41a3dd6222619a495ac98292458135d Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Tue, 21 Jul 2020 11:53:00 +0200 Subject: [PATCH] qmlpreview: fix translation for qml files in subdirectories Found path was ignored - so the location was wrong Keeping the kind of ugly in findValidI18nDirectoryAsUrl(const QString &locale) for now - to not change too much in that area. Change-Id: I491df1f928868a8d9afbbb7d25c8102bbe9b51a7 Reviewed-by: Marco Bubke --- .../qmlpreview/qmlpreviewconnectionmanager.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp index 0fcf6a36b89..69a33cfa58c 100644 --- a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp +++ b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp @@ -76,17 +76,22 @@ void QmlPreviewConnectionManager::createClients() QUrl QmlPreviewConnectionManager::findValidI18nDirectoryAsUrl(const QString &locale) { + QTC_ASSERT(!m_lastLoadedUrl.isEmpty(), return {};); + const QString shortLocale = locale.left(locale.indexOf("_")); QString path = m_lastLoadedUrl.path(); + QString foundPath; while (!path.isEmpty()) { path = path.left(qMax(0, path.lastIndexOf("/"))); QUrl url = m_lastLoadedUrl; + auto tryPath = [&](const QString &postfix) { url.setPath(path + "/i18n/qml_" + postfix); bool success = false; - m_projectFileFinder.findFile(url, &success); + foundPath = m_projectFileFinder.findFile(url, &success).first().toString(); + foundPath = foundPath.left(qMax(0, foundPath.lastIndexOf("/i18n"))); return success; }; @@ -101,7 +106,10 @@ QUrl QmlPreviewConnectionManager::findValidI18nDirectoryAsUrl(const QString &loc } QUrl url = m_lastLoadedUrl; - url.setPath(path); + if (foundPath.isEmpty()) + url.setPath(path); + else + url.setPath(foundPath); return url; }