ProjectExplorer: Add non-translatable text options to text edit fields

LineEdit and TextEdit have a couple of text options which start with
"tr". These strings can be translated via Qt Linguist.

In some cases, these text options contain macros or even JavaScript code
which must not be translated. Translation of these fields can
easily break the wizard.

This change adds the possibility to set non-translatable options for
LineEdits and TextEdits "(tr)Text", "(tr)DisabledText" and
"(tr)Placeholder" in the .json files.

Task-number: QTCREATORBUG-29649
Change-Id: I278a0bec848888cf96bdb49306e319c14a09236c
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2023-10-10 16:52:48 +02:00
parent 4aef48de5e
commit 03cca64eea
2 changed files with 35 additions and 11 deletions

View File

@@ -793,16 +793,24 @@
\list
\li \c trText specifies the default text to display.
\li \c trText specifies the translatable default text to display.
\li \c trDisabledText specifies the text to display in a disabled field.
\li \c text specifies the non-translatable default text to display.
\li \c trDisabledText specifies the translatable text to display in a
disabled field.
\li \c disabledText specifies the non-translatable text to display in
a disabled field.
\li \c completion lists existing \c namespaces for the class name line
edit and existing \c classes for the base class line edit. This
value replaces the history completer that is usually available for
such fields.
\li \c trPlaceholder specifies the placeholder text.
\li \c trPlaceholder specifies the translatable placeholder text.
\li \c placeholder specifies the non-translatable placeholder text.
\li \c validator specifies a QRegularExpression to validate the line
edit against.
@@ -886,10 +894,15 @@
\list
\li \c trText specifies the text to display.
\li \c trText specifies the translatable text to display.
\li \c trDisabledText specifies the text to display when the text edit
is disabled.
\li \c text specifies the non-translatable text to display.
\li \c trDisabledText specifies the translatable text to display when
the text edit is disabled.
\li \c disabledText specifies the non-translatable text to display when
the text edit is disabled.
\li \c richText is set to \c true for rich text, otherwise \c{false}.

View File

@@ -81,6 +81,17 @@ static Key fullSettingsKey(const QString &fieldKey)
return "Wizards/" + keyFromString(fieldKey);
}
static QString translatedOrUntranslatedText(QVariantMap &map, const QString &key)
{
if (key.size() >= 1) {
const QString trKey = "tr" + key.at(0).toUpper() + key.mid(1); // "text" -> "trText"
const QString trValue = JsonWizardFactory::localizedString(consumeValue(map, trKey).toString());
if (!trValue.isEmpty())
return trValue;
}
return consumeValue(map, key).toString();
}
// --------------------------------------------------------------------
// Helper:
@@ -489,9 +500,9 @@ bool LineEditField::parseData(const QVariant &data, QString *errorMessage)
QVariantMap tmp = data.toMap();
m_isPassword = consumeValue(tmp, "isPassword", false).toBool();
m_defaultText = JsonWizardFactory::localizedString(consumeValue(tmp, "trText").toString());
m_disabledText = JsonWizardFactory::localizedString(consumeValue(tmp, "trDisabledText").toString());
m_placeholderText = JsonWizardFactory::localizedString(consumeValue(tmp, "trPlaceholder").toString());
m_defaultText = translatedOrUntranslatedText(tmp, "text");
m_disabledText = translatedOrUntranslatedText(tmp, "disabledText");
m_placeholderText = translatedOrUntranslatedText(tmp, "placeholder");
m_historyId = consumeValue(tmp, "historyId").toString();
m_restoreLastHistoryItem = consumeValue(tmp, "restoreLastHistoryItem", false).toBool();
QString pattern = consumeValue(tmp, "validator").toString();
@@ -686,8 +697,8 @@ bool TextEditField::parseData(const QVariant &data, QString *errorMessage)
QVariantMap tmp = data.toMap();
m_defaultText = JsonWizardFactory::localizedString(consumeValue(tmp, "trText").toString());
m_disabledText = JsonWizardFactory::localizedString(consumeValue(tmp, "trDisabledText").toString());
m_defaultText = translatedOrUntranslatedText(tmp, "text");
m_disabledText = translatedOrUntranslatedText(tmp, "disabledText");
m_acceptRichText = consumeValue(tmp, "richText", true).toBool();
warnAboutUnsupportedKeys(tmp, name(), type());