Multilanguage: Add multilanguageSupport option to qmlproject

Change-Id: I1fc1861e17dc62cec91f5fa27f7e01360a42de78
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tuomo Pelkonen
2022-01-19 08:24:14 +02:00
parent d023dfca1e
commit bdba99c61b
7 changed files with 37 additions and 6 deletions

View File

@@ -99,6 +99,11 @@ QmlProjectItem *QmlProjectFileFormat::parseProjectFile(const Utils::FilePath &fi
if (fileSelectorsProperty.isValid())
projectItem->setFileSelectors(fileSelectorsProperty.value.toStringList());
const auto multilanguageSupportProperty = rootNode->property(
QLatin1String("multilanguageSupport"));
if (multilanguageSupportProperty.isValid())
projectItem->setMultilanguageSupport(multilanguageSupportProperty.value.toBool());
const auto languagesProperty = rootNode->property(QLatin1String("supportedLanguages"));
if (languagesProperty.isValid())
projectItem->setSupportedLanguages(languagesProperty.value.toStringList());

View File

@@ -77,6 +77,11 @@ void QmlProjectItem::setFileSelectors(const QStringList &selectors)
m_fileSelectors = selectors;
}
void QmlProjectItem::setMultilanguageSupport(const bool isEnabled)
{
m_multilanguageSupport = isEnabled;
}
void QmlProjectItem::setSupportedLanguages(const QStringList &languages)
{
if (m_supportedLanguages != languages)

View File

@@ -63,6 +63,9 @@ public:
QStringList fileSelectors() const { return m_fileSelectors; }
void setFileSelectors(const QStringList &selectors);
bool multilanguageSupport() const { return m_multilanguageSupport; }
void setMultilanguageSupport(const bool isEnabled);
QStringList supportedLanguages() const { return m_supportedLanguages; }
void setSupportedLanguages(const QStringList &languages);
@@ -94,6 +97,7 @@ protected:
QString m_targetDirectory;
QStringList m_importPaths;
QStringList m_fileSelectors;
bool m_multilanguageSupport;
QStringList m_supportedLanguages;
QString m_primaryLanguage;
QString m_mainFile;

View File

@@ -75,8 +75,9 @@ QmlMultiLanguageAspect::QmlMultiLanguageAspect(ProjectExplorer::Target *target)
{
setVisible(isMultilanguagePresent());
setSettingsKey(Constants::USE_MULTILANGUAGE_KEY);
setLabel(tr("Use MultiLanguage translation database."), BoolAspect::LabelPlacement::AtCheckBox);
setToolTip(tr("Enable loading application with special desktop SQLite translation database."));
setLabel(tr("Use MultiLanguage in Form Editor."), BoolAspect::LabelPlacement::AtCheckBox);
setToolTip(tr("By enabling this Form Editor can read translations\n"
"from MultiLanguage plugin."));
setDefaultValue(!databaseFilePath().isEmpty());
QVariantMap getDefaultValues;

View File

@@ -340,6 +340,13 @@ QStringList QmlBuildSystem::customFileSelectors() const
return {};
}
bool QmlBuildSystem::multilanguageSupport() const
{
if (m_projectItem)
return m_projectItem->multilanguageSupport();
return false;
}
QStringList QmlBuildSystem::supportedLanguages() const
{
if (m_projectItem)

View File

@@ -88,6 +88,7 @@ public:
Utils::EnvironmentItems environment() const;
QStringList customImportPaths() const;
QStringList customFileSelectors() const;
bool multilanguageSupport() const;
QStringList supportedLanguages() const;
void setSupportedLanguages(QStringList languages);
QString primaryLanguage() const;

View File

@@ -120,16 +120,24 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
connect(target, &Target::kitChanged, this, &RunConfiguration::update);
m_multiLanguageAspect = addAspect<QmlMultiLanguageAspect>(target);
auto buildSystem = qobject_cast<const QmlBuildSystem *>(activeBuildSystem());
if (buildSystem)
m_multiLanguageAspect->setValue(buildSystem->multilanguageSupport());
auto envAspect = addAspect<EnvironmentAspect>();
connect(m_multiLanguageAspect, &QmlMultiLanguageAspect::changed, envAspect, &EnvironmentAspect::environmentChanged);
connect(m_multiLanguageAspect,
&QmlMultiLanguageAspect::changed,
envAspect,
&EnvironmentAspect::environmentChanged);
auto envModifier = [this](Environment env) {
if (auto bs = dynamic_cast<const QmlBuildSystem *>(activeBuildSystem()))
if (auto bs = qobject_cast<const QmlBuildSystem *>(activeBuildSystem()))
env.modify(bs->environment());
if (m_multiLanguageAspect && m_multiLanguageAspect->value() && !m_multiLanguageAspect->databaseFilePath().isEmpty()) {
env.set("QT_MULTILANGUAGE_DATABASE", m_multiLanguageAspect->databaseFilePath().toString());
if (m_multiLanguageAspect && m_multiLanguageAspect->value()
&& !m_multiLanguageAspect->databaseFilePath().isEmpty()) {
env.set("QT_MULTILANGUAGE_DATABASE",
m_multiLanguageAspect->databaseFilePath().toString());
env.set("QT_MULTILANGUAGE_LANGUAGE", m_multiLanguageAspect->currentLocale());
} else {
env.unset("QT_MULTILANGUAGE_DATABASE");