Fix runtime warning reg. missing argument for QString in Palettes

Instead of something like the following:
qsTr("%n thing(s)", "comment", n)

The following was used:
qsTrc("context", "%n thing(s)").arg(n)

Which caused warnings like:
15:35:39.228 | WARN | main_thread | Qt | QString::arg: Argument missing: "Palettes Tree, contains %n palette(s)", 13

Because "%n" doesn't work together with `.arg`.

I updated the translation functions, so that we can now use this:
qsTrc("context", "%n thing(s)", "comment", n)

Which works without warnings.
This commit is contained in:
Casper Jeukendrup 2020-12-26 17:58:47 +01:00 committed by Igor Korsukov
parent 60c9ec4f4e
commit b469410032
7 changed files with 17 additions and 17 deletions

View file

@ -21,12 +21,12 @@
using namespace mu;
std::string mu::trc(const char* context, const char* key, const char* disambiguation)
std::string mu::trc(const char* context, const char* key, const char* disambiguation, int n)
{
return QCoreApplication::translate(context, key, disambiguation).toStdString();
return QCoreApplication::translate(context, key, disambiguation, n).toStdString();
}
QString mu::qtrc(const char* context, const char* key, const char* disambiguation)
QString mu::qtrc(const char* context, const char* key, const char* disambiguation, int n)
{
return QCoreApplication::translate(context, key, disambiguation);
return QCoreApplication::translate(context, key, disambiguation, n);
}

View file

@ -22,8 +22,8 @@
#include <QString>
namespace mu {
std::string trc(const char* context, const char* key, const char* disambiguation = nullptr);
QString qtrc(const char* context, const char* key, const char* disambiguation = nullptr);
std::string trc(const char* context, const char* key, const char* disambiguation = nullptr, int n = -1);
QString qtrc(const char* context, const char* key, const char* disambiguation = nullptr, int n = -1);
}
#endif // MU_FRAMEWORK_TRANSLATION_H

View file

@ -27,10 +27,10 @@ QmlTranslation::QmlTranslation(QObject* parent)
{
}
QString QmlTranslation::translate(const QString& context, const QString& text, const QString& disambiguation) const
QString QmlTranslation::translate(const QString& context, const QString& text, const QString& disambiguation, int n) const
{
return qtrc(context.toUtf8().constData(),
text.toUtf8().constData(),
disambiguation.isEmpty() ? nullptr : disambiguation.toUtf8().constData()
);
disambiguation.isEmpty() ? nullptr : disambiguation.toUtf8().constData(),
n);
}

View file

@ -29,7 +29,7 @@ class QmlTranslation : public QObject
public:
QmlTranslation(QObject* parent);
Q_INVOKABLE QString translate(const QString& context, const QString& text,const QString& disambiguation = QString()) const;
Q_INVOKABLE QString translate(const QString& context, const QString& text, const QString& disambiguation = QString(), int n = -1) const;
};
}
}

View file

@ -29,7 +29,7 @@ import "utils.js" as Utils
ListView {
id: paletteTree
Accessible.name: qsTrc("palette", "Palettes Tree, contains %n palette(s)").arg(count)
Accessible.name: qsTrc("palette", "Palettes Tree, contains %n palette(s)", "", count)
activeFocusOnTab: true // allow focus even when empty
@ -46,11 +46,11 @@ ListView {
property Item currentTreeItem: currentItem // most recently focused item at any level of the tree
property string filter: ""
property bool searchOpenned: false
property bool searchOpened: false
onSearchOpennedChanged: {
onSearchOpenedChanged: {
if (paletteWorkspace) {
paletteWorkspace.setSearching(searchOpenned)
paletteWorkspace.setSearching(searchOpened)
}
}

View file

@ -87,7 +87,7 @@ Rectangle {
text: qsTrc("palette", "Start typing to search all palettes")
visible: palettesWidgetHeader.searchOpenned && !Boolean(palettesWidgetHeader.searchText)
visible: palettesWidgetHeader.searchOpened && !Boolean(palettesWidgetHeader.searchText)
}
PaletteTree {
@ -97,7 +97,7 @@ Rectangle {
filter: palettesWidgetHeader.searchText
enableAnimations: !palettesWidgetHeader.searching
searchOpenned: palettesWidgetHeader.searchOpenned
searchOpened: palettesWidgetHeader.searchOpened
anchors {
top: palettesWidgetHeader.bottom

View file

@ -32,7 +32,7 @@ Item {
property PaletteWorkspace paletteWorkspace: null
property string searchText: searchTextInput.searchText
readonly property bool searching: searchTextInput.activeFocus
property bool searchOpenned: searchTextInput.visible
property bool searchOpened: searchTextInput.visible
property alias popupMaxHeight: palettePopup.maxHeight