forked from qt-creator/qt-creator
Fix in-wizard translation support
We in principle support a map of locale->string for keys starting with "tr" like "trDisplayName". This didn't work everywhere. We may not cast the value for these keys to QString before passing it to `localizedString`, since that would result in an empty string if the value is such a map. Also fix the documentation since we remove all parts from '_' (to also get rid of encoding parts). Fixes: QTCREATORBUG-23575 Change-Id: I2be795053e645c8bf81417d0db69cd7e63eff022 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -52,13 +52,13 @@
|
||||
translations in the .json file using the following syntax:
|
||||
|
||||
\code
|
||||
"trDisplayName": { "C": "default", "en_US": "english", "de_DE": "deutsch" }
|
||||
"trDisplayName": { "C": "default", "en": "english", "de": "deutsch" }
|
||||
\endcode
|
||||
|
||||
For example:
|
||||
|
||||
\code
|
||||
"trDisplayName": { "C": "Project Location", "en_US": "Project Location", "de_DE": "Projekt Verzeichnis" }
|
||||
"trDisplayName": { "C": "Project Location", "en": "Project Location", "de": "Projektverzeichnis" }
|
||||
\endcode
|
||||
|
||||
\section1 Creating Wizards
|
||||
|
@@ -85,7 +85,7 @@ 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());
|
||||
const QString trValue = JsonWizardFactory::localizedString(consumeValue(map, trKey));
|
||||
if (!trValue.isEmpty())
|
||||
return trValue;
|
||||
}
|
||||
@@ -188,9 +188,10 @@ JsonFieldPage::Field *JsonFieldPage::Field::parse(const QVariant &input, QString
|
||||
*errorMessage = Tr::tr("Field \"%1\" has unsupported type \"%2\".").arg(name).arg(type);
|
||||
return nullptr;
|
||||
}
|
||||
data->setTexts(name,
|
||||
JsonWizardFactory::localizedString(consumeValue(tmp, DISPLAY_NAME_KEY).toString()),
|
||||
JsonWizardFactory::localizedString(consumeValue(tmp, TOOLTIP_KEY).toString()));
|
||||
data->setTexts(
|
||||
name,
|
||||
JsonWizardFactory::localizedString(consumeValue(tmp, DISPLAY_NAME_KEY)),
|
||||
JsonWizardFactory::localizedString(consumeValue(tmp, TOOLTIP_KEY)));
|
||||
|
||||
data->setVisibleExpression(consumeValue(tmp, VISIBLE_KEY, true));
|
||||
data->setEnabledExpression(consumeValue(tmp, ENABLED_KEY, true));
|
||||
@@ -974,7 +975,7 @@ std::unique_ptr<QStandardItem> createStandardItemFromListItem(const QVariant &it
|
||||
auto standardItem = std::make_unique<QStandardItem>();
|
||||
if (item.typeId() == QMetaType::QVariantMap) {
|
||||
QVariantMap tmp = item.toMap();
|
||||
const QString key = JsonWizardFactory::localizedString(consumeValue(tmp, "trKey", QString()).toString());
|
||||
const QString key = JsonWizardFactory::localizedString(consumeValue(tmp, "trKey"));
|
||||
const QVariant value = consumeValue(tmp, "value", key);
|
||||
|
||||
if (key.isNull() || key.isEmpty()) {
|
||||
@@ -985,7 +986,7 @@ std::unique_ptr<QStandardItem> createStandardItemFromListItem(const QVariant &it
|
||||
standardItem->setData(value, ListField::ValueRole);
|
||||
standardItem->setData(consumeValue(tmp, "condition", true), ListField::ConditionRole);
|
||||
standardItem->setData(consumeValue(tmp, "icon"), ListField::IconStringRole);
|
||||
standardItem->setToolTip(JsonWizardFactory::localizedString(consumeValue(tmp, "trToolTip", QString()).toString()));
|
||||
standardItem->setToolTip(JsonWizardFactory::localizedString(consumeValue(tmp, "trToolTip")));
|
||||
warnAboutUnsupportedKeys(tmp, QString(), "List");
|
||||
} else {
|
||||
const QString keyvalue = item.toString();
|
||||
|
@@ -763,10 +763,9 @@ QString JsonWizardFactory::localizedString(const QVariant &value)
|
||||
return {};
|
||||
if (value.typeId() == QMetaType::QVariantMap) {
|
||||
QVariantMap tmp = value.toMap();
|
||||
const QString locale = languageSetting().toLower();
|
||||
QStringList locales;
|
||||
locales << locale << QLatin1String("en") << QLatin1String("C") << tmp.keys();
|
||||
for (const QString &locale : std::as_const(locales)) {
|
||||
const QString currentLocale = languageSetting().toLower();
|
||||
const QStringList locales{currentLocale, "en", "C"};
|
||||
for (const QString &locale : locales) {
|
||||
QString result = tmp.value(locale, QString()).toString();
|
||||
if (!result.isEmpty())
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user