You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libqtxdg-packaging/debian/patches/ubuntu-gettext-translations...

42 lines
1.4 KiB

Description: Add support for translations defined via X-Ubuntu-Gettext-Domain
Author: Simon Quigley <tsimonq2@lubuntu.me>
Origin: vendor
Forwarded: https://github.com/lxqt/libqtxdg/pull/292
Last-Update: 2023-03-06
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/qtxdg/xdgdesktopfile.cpp
+++ b/src/qtxdg/xdgdesktopfile.cpp
@@ -38,6 +38,7 @@
#include <cstdlib>
#include <unistd.h>
+#include <libintl.h>
#include <QDebug>
#include <QDBusInterface>
2 years ago
@@ -920,7 +921,22 @@ QString XdgDesktopFile::localizedKey(con
QVariant XdgDesktopFile::localizedValue(const QString& key, const QVariant& defaultValue) const
{
- return value(localizedKey(key), defaultValue);
+ // If the file is translated via gettext, override locally-defined translations
+ if (contains(QLatin1String("X-Ubuntu-Gettext-Domain")))
+ {
+ QString domain = value(QLatin1String("X-Ubuntu-Gettext-Domain")).toString();
+ QString val = value(key, defaultValue).toString().trimmed();
+ if (!val.isEmpty()) {
+ QByteArray _domain = domain.toUtf8();
+ QByteArray _val = val.toUtf8();
+ char *translated = dgettext(_domain.constData(), _val.constData());
+ return QVariant(QString::fromUtf8(translated));
+ } else {
+ return QVariant();
+ }
+ } else {
+ return value(localizedKey(key), defaultValue);
+ }
}
2 years ago