[education/rkward] /: Fix spurious I18N_ARGUMENT_MISSING message in plugins

Thomas Friedrichsmeier null at kde.org
Sat Apr 9 17:01:44 BST 2022


Git commit d112cd1523910c33b285cbd7b994641911a59602 by Thomas Friedrichsmeier.
Committed on 09/04/2022 at 16:01.
Pushed by tfry into branch 'master'.

Fix spurious I18N_ARGUMENT_MISSING message in plugins

M  +1    -0    ChangeLog
M  +21   -17   rkward/misc/rkmessagecatalog.cpp
M  +5    -5    rkward/misc/rkmessagecatalog.h
M  +4    -16   rkward/scriptbackends/common.js
M  +9    -9    rkward/scriptbackends/qtscripti18n.h

https://invent.kde.org/education/rkward/commit/d112cd1523910c33b285cbd7b994641911a59602

diff --git a/ChangeLog b/ChangeLog
index c5279e66..53d46cae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
 --- Version 0.7.3 - UNRELEASED
+- Fixed: Spurious string I18N_ARGUMENT_MISMATCH in several plugins
 - Add setting to allow hiding R Console scrollbar minimap
 - Fixed: Accordeon control (used in "Recode categorical data") never expanded
 - "Spontaneous" output, such as from running examples in the enhanced help system in R 4.2.0, is shown in the R Console
diff --git a/rkward/misc/rkmessagecatalog.cpp b/rkward/misc/rkmessagecatalog.cpp
index 55fa52e5..4e4b900c 100644
--- a/rkward/misc/rkmessagecatalog.cpp
+++ b/rkward/misc/rkmessagecatalog.cpp
@@ -1,6 +1,6 @@
 /*
 rkmessagecatalog - This file is part of RKWard (https://rkward.kde.org). Created: Mon Jun 24 2013
-SPDX-FileCopyrightText: 2013-2018 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2013-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -29,28 +29,32 @@ RKMessageCatalog::~RKMessageCatalog () {
 	RK_TRACE (MISC);
 }
 
-QString RKMessageCatalog::translate (const QString &msgctxt, const QString &msgid) const {
-	RK_TRACE (MISC);
-
-	return i18ndc (catalog_name, msgctxt.toUtf8 (), msgid.toUtf8 ());
+QString RKMessageCatalog::translate(const QString &msgctxt, const QString &msgid, const QStringList &args) const {
+	RK_TRACE(MISC);
+	auto ret = ki18ndc(catalog_name, msgctxt.toUtf8(), msgid.toUtf8());
+	for(int i = 0; i < args.size(); ++i) ret = ret.subs(args[i]);
+	return ret.toString();
 }
 
-QString RKMessageCatalog::translate (const QString &msgctxt, const QString &msgid_singular, const QString &msgid_plural, unsigned long int count) const {
-	RK_TRACE (MISC);
-
-	return i18ndcp (catalog_name, msgctxt.toUtf8 (), msgid_singular.toUtf8 (), msgid_plural.toUtf8 (), count);
+QString RKMessageCatalog::translate(const QString &msgctxt, const QString &msgid_singular, const QString &msgid_plural, unsigned long int count, const QStringList &args) const {
+	RK_TRACE(MISC);
+	auto ret = ki18ndcp(catalog_name, msgctxt.toUtf8(), msgid_singular.toUtf8(), msgid_plural.toUtf8()).subs(count);
+	for(int i = 0; i < args.size(); ++i) ret = ret.subs(args[i]);
+	return ret.toString();
 }
 
-QString RKMessageCatalog::translate (const QString &msgid) const {
-	RK_TRACE (MISC);
-
-	return i18nd (catalog_name, msgid.toUtf8 ());
+QString RKMessageCatalog::translate(const QString &msgid, const QStringList &args) const {
+	RK_TRACE(MISC);
+	auto ret = ki18nd(catalog_name, msgid.toUtf8());
+	for(int i = 0; i < args.size(); ++i) ret = ret.subs(args[i]);
+	return ret.toString();
 }
 
-QString RKMessageCatalog::translate (const QString &msgid_singular, const QString &msgid_plural, unsigned long int count) const {
-	RK_TRACE (MISC);
-
-	return i18ndp (catalog_name, msgid_singular.toUtf8 (), msgid_plural.toUtf8 (), count);
+QString RKMessageCatalog::translate(const QString &msgid_singular, const QString &msgid_plural, unsigned long int count, const QStringList &args) const {
+	RK_TRACE(MISC);
+	auto ret = ki18ndp(catalog_name, msgid_singular.toUtf8(), msgid_plural.toUtf8()).subs(count);
+	for(int i = 0; i < args.size(); ++i) ret = ret.subs(args[i]);
+	return ret.toString();
 }
 
 RKMessageCatalog* RKMessageCatalog::CatalogHash::getCatalog (const QString& name, const QString& pathhint) {
diff --git a/rkward/misc/rkmessagecatalog.h b/rkward/misc/rkmessagecatalog.h
index dd7911b1..376d2146 100644
--- a/rkward/misc/rkmessagecatalog.h
+++ b/rkward/misc/rkmessagecatalog.h
@@ -1,6 +1,6 @@
 /*
 rkmessagecatalog - This file is part of the RKWard project. Created: Mon Jun 24 2013
-SPDX-FileCopyrightText: 2013-2018 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2013-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -20,10 +20,10 @@ SPDX-License-Identifier: GPL-2.0-or-later
  */
 class RKMessageCatalog {
 public:
-	QString translate (const QString &msgid) const;
-	QString translate (const QString &msgctxt, const QString &msgid) const;
-	QString translate (const QString &msgid_singular, const QString &msgid_plural, unsigned long int count) const;
-	QString translate (const QString &msgctxt, const QString &msgid_singular, const QString &msgid_plural, unsigned long int count) const;
+	QString translate(const QString &msgid, const QStringList &args=QStringList()) const;
+	QString translate(const QString &msgctxt, const QString &msgid, const QStringList &args=QStringList()) const;
+	QString translate(const QString &msgid_singular, const QString &msgid_plural, unsigned long int count, const QStringList &args=QStringList()) const;
+	QString translate(const QString &msgctxt, const QString &msgid_singular, const QString &msgid_plural, unsigned long int count, const QStringList &args=QStringList()) const;
 
 /** Get the catalog identified by name. This could be an already open catalog, or a new one. In the latter case, the catalog is expected at pathhint. In the former case, pathhint is ignored. This function is guaranteed to return a non-null RKMessageCatalog, although that does not imply the catalog could actually be loaded. */
 	static RKMessageCatalog *getCatalog (const QString &name, const QString &pathhint);
diff --git a/rkward/scriptbackends/common.js b/rkward/scriptbackends/common.js
index 2a840785..3654380a 100644
--- a/rkward/scriptbackends/common.js
+++ b/rkward/scriptbackends/common.js
@@ -36,10 +36,7 @@ quote = function (text) {
 }
 
 i18n = function (msgid) {
-	var ret = _i18n.i18n (msgid);
-	for (var i = 1; i < arguments.length; i++) {
-		ret = ret.replace(new RegExp("%" + i, 'g'), arguments[i]);
-	}
+	var ret = _i18n.i18n (msgid, Array.prototype.slice.call(arguments, 1));
 	if (msgid.noquote) {
 		ret.noquote = msgid.noquote;
 		return (ret);
@@ -50,10 +47,7 @@ i18n = function (msgid) {
 }
 
 i18nc = function (msgctxt, msgid) {
-	var ret = _i18n.i18nc (msgctxt, msgid);
-	for (var i = 2; i < arguments.length; i++) {
-		ret = ret.replace(new RegExp("%" + (i - 1), 'g'), arguments[i]);
-	}
+	var ret = _i18n.i18nc (msgctxt, msgid, Array.prototype.slice.call(arguments, 2));
 	if (msgid.noquote) {
 		ret.noquote = msgid.noquote;
 		return (ret);
@@ -62,10 +56,7 @@ i18nc = function (msgctxt, msgid) {
 }
 
 i18np = function (msgid, msgid_plural, n) {
-	var ret = _i18n.i18np (msgid, msgid_plural, n);
-	for (var i = 3; i < arguments.length; i++) {
-		ret = ret.replace(new RegExp("%" + (i - 1), 'g'), arguments[i]);	// start replacing at %2. %1 already handled.
-	}
+	var ret = _i18n.i18np (msgid, msgid_plural, n, Array.prototype.slice.call(arguments, 3));
 	if (msgid.noquote) {
 		ret.noquote = msgid.noquote;
 		return (ret);
@@ -74,10 +65,7 @@ i18np = function (msgid, msgid_plural, n) {
 }
 
 i18ncp = function (msgctxt, msgid, msgid_plural, n) {
-	var ret = _i18n.i18ncp (msgctxt, msgid, msgid_plural, n);
-	for (var i = 4; i < arguments.length; i++) {
-		ret = ret.replace(new RegExp("%" + (i - 2), 'g'), arguments[i]);
-	}
+	var ret = _i18n.i18ncp (msgctxt, msgid, msgid_plural, n, Array.prototype.slice.call(arguments, 4));
 	if (msgid.noquote) {
 		ret.noquote = msgid.noquote;
 		return (ret);
diff --git a/rkward/scriptbackends/qtscripti18n.h b/rkward/scriptbackends/qtscripti18n.h
index 08b90056..b03e246a 100644
--- a/rkward/scriptbackends/qtscripti18n.h
+++ b/rkward/scriptbackends/qtscripti18n.h
@@ -1,6 +1,6 @@
 /*
 qtscripti18n - This file is part of the RKWard project. Created: Wed Oct 29 2014
-SPDX-FileCopyrightText: 2014 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2014-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -21,17 +21,17 @@ public:
 	RKMessageCatalogObject (const RKMessageCatalog *_catalog, QObject *parent) : QObject (parent), catalog (_catalog) {};
 	virtual ~RKMessageCatalogObject () {};
 
-	Q_INVOKABLE QString i18n (const QString &msgid) const {
-		return (catalog->translate (msgid));
+	Q_INVOKABLE QString i18n(const QString &msgid, const QStringList &args) const {
+		return (catalog->translate(msgid, args));
 	};
-	Q_INVOKABLE QString i18nc (const QString &msgctxt, const QString &msgid) const {
-		return (catalog->translate (msgctxt, msgid));
+	Q_INVOKABLE QString i18nc(const QString &msgctxt, const QString &msgid, const QStringList &args) const {
+		return (catalog->translate(msgctxt, msgid, args));
 	};
-	Q_INVOKABLE QString i18np (const QString &msgid_singular, const QString &msgid_plural, uint count) const {
-		return (catalog->translate (msgid_singular, msgid_plural, count));
+	Q_INVOKABLE QString i18np(const QString &msgid_singular, const QString &msgid_plural, uint count, const QStringList &args) const {
+		return (catalog->translate(msgid_singular, msgid_plural, count, args));
 	};
-	Q_INVOKABLE QString i18ncp (const QString &msgctxt, const QString &msgid_singular, const QString &msgid_plural, uint count) const {
-		return (catalog->translate (msgctxt, msgid_singular, msgid_plural, count));
+	Q_INVOKABLE QString i18ncp(const QString &msgctxt, const QString &msgid_singular, const QString &msgid_plural, uint count, const QStringList &args) const {
+		return (catalog->translate(msgctxt, msgid_singular, msgid_plural, count, args));
 	};
 /** Add an RKMessageCatalog, and the required glue code to the given QScriptEngine. */
 	static void addI18nToScriptEngine (RKJSEngine *engine, const RKMessageCatalog *catalog);


More information about the rkward-tracker mailing list