generic: adjust to Katie changes

also fixes build with QT_NO_TRANSLATION, symbols will not exists in the
library even if QT_NO_TRANSLATION is undefined and redefined

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2020-11-29 00:44:13 +00:00
parent db2ca8ddfb
commit d00c56fe0b
7 changed files with 137 additions and 135 deletions

View file

@ -179,8 +179,10 @@ KLocale *KGlobal::locale()
if (coreApp->thread() != QThread::currentThread()) {
qFatal("KGlobal::locale() must be called from the main thread before using i18n() in threads. KApplication"
" takes care of this. If not using KApplication, call KGlobal::locale() during initialization.");
#ifndef QT_NO_TRANSLATION
} else {
QCoreApplication::installTranslator(new KDETranslator(coreApp));
#endif
}
}
foreach(const QString &catalog, d->catalogsToInsert) {

View file

@ -32,10 +32,9 @@ namespace KGlobal
#include "kglobal.h"
#include "klocale.h"
#undef QT_NO_TRANSLATION
#include <QtCore/QTranslator>
#define QT_NO_TRANSLATION
#ifndef QT_NO_TRANSLATION
class KDETranslator : public QTranslator
{
public:
@ -44,10 +43,19 @@ public:
setObjectName(QLatin1String("kdetranslator"));
}
virtual QString translate(const char* context,
const char *sourceText,
const char* message) const
// provides virtuals for old and new method
virtual QString translate(const char *context,
const char *sourceText) const
{
return KGlobal::locale()->translateQt(context, sourceText, 0);
}
virtual QString translate(const char *context,
const char *sourceText,
const char *message,
const char *disambiguation = 0) const
{
Q_UNUSED(disambiguation);
return KGlobal::locale()->translateQt(context, sourceText, message);
}
@ -56,5 +64,6 @@ public:
return false;
}
};
#endif // QT_NO_TRANSLATION
#endif // KGLOBAL_P_H

View file

@ -720,10 +720,6 @@ QString FormModule::tr(const QString& str)
{
return QObject::tr(str.toUtf8());
}
QString FormModule::tr(const QString& str, const QString& comment)
{
return QObject::tr(str.toUtf8(),comment.toUtf8());
}
QWidget* FormModule::createWidgetFromUI(QWidget* parent, const QString& xml)
{
@ -737,7 +733,7 @@ QWidget* FormModule::createWidgetFromUI(QWidget* parent, const QString& xml)
while(--i>=0)
{
QDomElement e=strings.at(i).toElement();
QString i18nd=e.attribute("comment").isEmpty()?QObject::tr(e.text().toUtf8()):QObject::tr(e.text().toUtf8(),e.attribute("comment").toUtf8());
QString i18nd=QObject::tr(e.text().toUtf8());
if (i18nd==e.text())
continue;
QDomNode n = e.firstChild();

View file

@ -549,12 +549,6 @@ namespace Kross {
*/
QString tr(const QString& str);
/**
* \return i18n'ed version of the string, differentiated by the comment text (like '\@title:window')
*/
QString tr(const QString& str,const QString& comment);
/**
* Show a messagebox.
*

View file

@ -39,9 +39,10 @@
#include <QtDBus/QDBusMetaType>
#include <QtDBus/QDBusPendingReply>
#include <QtDBus/QDBusArgument>
#include <QtXml/qdom.h>
#include <klocalizedstring.h>
using namespace Solid::Backends::UDisks2;
// Adapted from KLocale as Solid needs to be Qt-only
@ -61,31 +62,31 @@ static QString formatByteSize(double size)
{
size /= 1073741824.0;
if ( size > 1024 ) // Tebi-byte
s = QCoreApplication::translate("", "%1 TiB").arg(QLocale().toString(size / 1024.0, 'f', 1));
s = i18n("%1 TiB", QLocale().toString(size / 1024.0, 'f', 1));
else
s = QCoreApplication::translate("", "%1 GiB").arg(QLocale().toString(size, 'f', 1));
s = i18n("%1 GiB", QLocale().toString(size, 'f', 1));
}
// Mebi-byte
else if ( size >= 1048576.0 )
{
size /= 1048576.0;
s = QCoreApplication::translate("", "%1 MiB").arg(QLocale().toString(size, 'f', 1));
s = i18n("%1 MiB", QLocale().toString(size, 'f', 1));
}
// Kibi-byte
else if ( size >= 1024.0 )
{
size /= 1024.0;
s = QCoreApplication::translate("", "%1 KiB").arg(QLocale().toString(size, 'f', 1));
s = i18n("%1 KiB", QLocale().toString(size, 'f', 1));
}
// Just byte
else if ( size > 0 )
{
s = QCoreApplication::translate("", "%1 B").arg(QLocale().toString(size, 'f', 1));
s = i18n("%1 B", QLocale().toString(size, 'f', 1));
}
// Nothing
else
{
s = QCoreApplication::translate("", "0 B");
s = i18n("0 B");
}
return s;
}
@ -276,55 +277,55 @@ QString Device::storageDescription() const
QString first;
QString second;
first = QCoreApplication::translate("", "CD-ROM", "First item of %1%2 Drive sentence");
first = i18n("CD-ROM");
if (mediumTypes & Solid::OpticalDrive::Cdr)
first = QCoreApplication::translate("", "CD-R", "First item of %1%2 Drive sentence");
first = i18n("CD-R");
if (mediumTypes & Solid::OpticalDrive::Cdrw)
first = QCoreApplication::translate("", "CD-RW", "First item of %1%2 Drive sentence");
first = i18n("CD-RW");
if (mediumTypes & Solid::OpticalDrive::Dvd)
second = QCoreApplication::translate("", "/DVD-ROM", "Second item of %1%2 Drive sentence");
second = i18n("/DVD-ROM");
if (mediumTypes & Solid::OpticalDrive::Dvdplusr)
second = QCoreApplication::translate("", "/DVD+R", "Second item of %1%2 Drive sentence");
second = i18n("/DVD+R");
if (mediumTypes & Solid::OpticalDrive::Dvdplusrw)
second = QCoreApplication::translate("", "/DVD+RW", "Second item of %1%2 Drive sentence");
second = i18n("/DVD+RW");
if (mediumTypes & Solid::OpticalDrive::Dvdr)
second = QCoreApplication::translate("", "/DVD-R", "Second item of %1%2 Drive sentence");
second = i18n("/DVD-R");
if (mediumTypes & Solid::OpticalDrive::Dvdrw)
second = QCoreApplication::translate("", "/DVD-RW", "Second item of %1%2 Drive sentence");
second = i18n("/DVD-RW");
if (mediumTypes & Solid::OpticalDrive::Dvdram)
second = QCoreApplication::translate("", "/DVD-RAM", "Second item of %1%2 Drive sentence");
second = i18n("/DVD-RAM");
if ((mediumTypes & Solid::OpticalDrive::Dvdr) && (mediumTypes & Solid::OpticalDrive::Dvdplusr))
{
if(mediumTypes & Solid::OpticalDrive::Dvdplusdl)
second = QObject::trUtf8("/DVD±R DL", "Second item of %1%2 Drive sentence");
second = i18n("/DVD±R DL");
else
second = QObject::trUtf8("/DVD±R", "Second item of %1%2 Drive sentence");
second = i18n("/DVD±R");
}
if ((mediumTypes & Solid::OpticalDrive::Dvdrw) && (mediumTypes & Solid::OpticalDrive::Dvdplusrw))
{
if((mediumTypes & Solid::OpticalDrive::Dvdplusdl) || (mediumTypes & Solid::OpticalDrive::Dvdplusdlrw))
second = QObject::trUtf8("/DVD±RW DL", "Second item of %1%2 Drive sentence");
second = i18n("/DVD±RW DL");
else
second = QObject::trUtf8("/DVD±RW", "Second item of %1%2 Drive sentence");
second = i18n("/DVD±RW");
}
if (mediumTypes & Solid::OpticalDrive::Bd)
second = QCoreApplication::translate("", "/BD-ROM", "Second item of %1%2 Drive sentence");
second = i18n("/BD-ROM");
if (mediumTypes & Solid::OpticalDrive::Bdr)
second = QCoreApplication::translate("", "/BD-R", "Second item of %1%2 Drive sentence");
second = i18n("/BD-R");
if (mediumTypes & Solid::OpticalDrive::Bdre)
second = QCoreApplication::translate("", "/BD-RE", "Second item of %1%2 Drive sentence");
second = i18n("/BD-RE");
if (mediumTypes & Solid::OpticalDrive::HdDvd)
second = QCoreApplication::translate("", "/HD DVD-ROM", "Second item of %1%2 Drive sentence");
second = i18n("/HD DVD-ROM");
if (mediumTypes & Solid::OpticalDrive::HdDvdr)
second = QCoreApplication::translate("", "/HD DVD-R", "Second item of %1%2 Drive sentence");
second = i18n("/HD DVD-R");
if (mediumTypes & Solid::OpticalDrive::HdDvdrw)
second = QCoreApplication::translate("", "/HD DVD-RW", "Second item of %1%2 Drive sentence");
second = i18n("/HD DVD-RW");
if (drive_is_hotpluggable)
description = QCoreApplication::translate("", "External %1%2 Drive", "%1 is CD-ROM/CD-R/etc; %2 is '/DVD-ROM'/'/DVD-R'/etc (with leading slash)").arg(first).arg(second);
description = i18n("External %1%2 Drive", first, second);
else
description = QCoreApplication::translate("", "%1%2 Drive", "%1 is CD-ROM/CD-R/etc; %2 is '/DVD-ROM'/'/DVD-R'/etc (with leading slash)").arg(first).arg(second);
description = i18n("%1%2 Drive", first, second);
return description;
}
@ -332,9 +333,9 @@ QString Device::storageDescription() const
if (drive_type == Solid::StorageDrive::Floppy)
{
if (drive_is_hotpluggable)
description = QCoreApplication::translate("", "External Floppy Drive");
description = i18n("External Floppy Drive");
else
description = QCoreApplication::translate("", "Floppy Drive");
description = i18n("Floppy Drive");
return description;
}
@ -347,14 +348,14 @@ QString Device::storageDescription() const
if (!size_str.isEmpty())
{
if (drive_is_hotpluggable)
description = QCoreApplication::translate("", "%1 External Hard Drive", "%1 is the size").arg(size_str);
description = i18n("%1 External Hard Drive", size_str);
else
description = QCoreApplication::translate("", "%1 Hard Drive", "%1 is the size").arg(size_str);
description = i18n("%1 Hard Drive", size_str);
} else {
if (drive_is_hotpluggable)
description = QCoreApplication::translate("", "External Hard Drive");
description = i18n("External Hard Drive");
else
description = QCoreApplication::translate("", "Hard Drive");
description = i18n("Hard Drive");
}
return description;
@ -382,13 +383,13 @@ QString Device::storageDescription() const
}
else
{
vendormodel_str = QCoreApplication::translate("", "%1 %2", "%1 is the vendor, %2 is the model of the device").arg(vendor_str).arg(model);
vendormodel_str = i18n("%1 %2", vendor_str, model);
}
}
}
if (vendormodel_str.isEmpty())
description = QCoreApplication::translate("", "Drive");
description = i18n("Drive");
else
description = vendormodel_str;
@ -417,116 +418,116 @@ QString Device::volumeDescription() const
{
case Solid::OpticalDisc::UnknownDiscType:
case Solid::OpticalDisc::CdRom:
description = QCoreApplication::translate("", "CD-ROM");
description = i18n("CD-ROM");
break;
case Solid::OpticalDisc::CdRecordable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank CD-R");
description = i18n("Blank CD-R");
else
description = QCoreApplication::translate("", "CD-R");
description = i18n("CD-R");
break;
case Solid::OpticalDisc::CdRewritable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank CD-RW");
description = i18n("Blank CD-RW");
else
description = QCoreApplication::translate("", "CD-RW");
description = i18n("CD-RW");
break;
case Solid::OpticalDisc::DvdRom:
description = QCoreApplication::translate("", "DVD-ROM");
description = i18n("DVD-ROM");
break;
case Solid::OpticalDisc::DvdRam:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank DVD-RAM");
description = i18n("Blank DVD-RAM");
else
description = QCoreApplication::translate("", "DVD-RAM");
description = i18n("DVD-RAM");
break;
case Solid::OpticalDisc::DvdRecordable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank DVD-R");
description = i18n("Blank DVD-R");
else
description = QCoreApplication::translate("", "DVD-R");
description = i18n("DVD-R");
break;
case Solid::OpticalDisc::DvdPlusRecordableDuallayer:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank DVD+R Dual-Layer");
description = i18n("Blank DVD+R Dual-Layer");
else
description = QCoreApplication::translate("", "DVD+R Dual-Layer");
description = i18n("DVD+R Dual-Layer");
break;
case Solid::OpticalDisc::DvdRewritable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank DVD-RW");
description = i18n("Blank DVD-RW");
else
description = QCoreApplication::translate("", "DVD-RW");
description = i18n("DVD-RW");
break;
case Solid::OpticalDisc::DvdPlusRecordable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank DVD+R");
description = i18n("Blank DVD+R");
else
description = QCoreApplication::translate("", "DVD+R");
description = i18n("DVD+R");
break;
case Solid::OpticalDisc::DvdPlusRewritable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank DVD+RW");
description = i18n("Blank DVD+RW");
else
description = QCoreApplication::translate("", "DVD+RW");
description = i18n("DVD+RW");
break;
case Solid::OpticalDisc::DvdPlusRewritableDuallayer:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank DVD+RW Dual-Layer");
description = i18n("Blank DVD+RW Dual-Layer");
else
description = QCoreApplication::translate("", "DVD+RW Dual-Layer");
description = i18n("DVD+RW Dual-Layer");
break;
case Solid::OpticalDisc::BluRayRom:
description = QCoreApplication::translate("", "BD-ROM");
description = i18n("BD-ROM");
break;
case Solid::OpticalDisc::BluRayRecordable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank BD-R");
description = i18n("Blank BD-R");
else
description = QCoreApplication::translate("", "BD-R");
description = i18n("BD-R");
break;
case Solid::OpticalDisc::BluRayRewritable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank BD-RE");
description = i18n("Blank BD-RE");
else
description = QCoreApplication::translate("", "BD-RE");
description = i18n("BD-RE");
break;
case Solid::OpticalDisc::HdDvdRom:
description = QCoreApplication::translate("", "HD DVD-ROM");
description = i18n("HD DVD-ROM");
break;
case Solid::OpticalDisc::HdDvdRecordable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank HD DVD-R");
description = i18n("Blank HD DVD-R");
else
description = QCoreApplication::translate("", "HD DVD-R");
description = i18n("HD DVD-R");
break;
case Solid::OpticalDisc::HdDvdRewritable:
if (disc.isBlank())
description = QCoreApplication::translate("", "Blank HD DVD-RW");
description = i18n("Blank HD DVD-RW");
else
description = QCoreApplication::translate("", "HD DVD-RW");
description = i18n("HD DVD-RW");
break;
}
// Special case for pure audio disc
if (disc.availableContent() == Solid::OpticalDisc::Audio)
description = QCoreApplication::translate("", "Audio CD");
description = i18n("Audio CD");
return description;
}
@ -538,33 +539,33 @@ QString Device::volumeDescription() const
if (isEncryptedContainer())
{
if (!size_str.isEmpty())
description = QCoreApplication::translate("", "%1 Encrypted Drive", "%1 is the size").arg(size_str);
description = i18n("%1 Encrypted Drive", size_str);
else
description = QCoreApplication::translate("", "Encrypted Drive");
description = i18n("Encrypted Drive");
}
else if (drive_type == Solid::StorageDrive::HardDisk && !drive_is_removable)
{
if (!size_str.isEmpty())
{
if (drive_is_hotpluggable)
description = QCoreApplication::translate("", "%1 External Hard Drive", "%1 is the size").arg(size_str);
description = i18n("%1 External Hard Drive", size_str);
else
description = QCoreApplication::translate("", "%1 Hard Drive", "%1 is the size").arg(size_str);
description = i18n("%1 Hard Drive", size_str);
}
else
{
if (drive_is_hotpluggable)
description = QCoreApplication::translate("", "External Hard Drive");
description = i18n("External Hard Drive");
else
description = QCoreApplication::translate("", "Hard Drive");
description = i18n("Hard Drive");
}
}
else
{
if (drive_is_removable)
description = QCoreApplication::translate("", "%1 Removable Media", "%1 is the size").arg(size_str);
description = i18n("%1 Removable Media", size_str);
else
description = QCoreApplication::translate("", "%1 Media", "%1 is the size").arg(size_str);
description = i18n("%1 Media", size_str);
}
return description;
@ -698,33 +699,33 @@ QString Device::parentUdi() const
QString Device::errorToString(const QString & error) const
{
if (error == UD2_ERROR_UNAUTHORIZED || error == UD2_ERROR_NOT_AUTHORIZED)
return QCoreApplication::translate("", "You are not authorized to perform this operation");
return i18n("You are not authorized to perform this operation");
else if (error == UD2_ERROR_BUSY)
return QCoreApplication::translate("", "The device is currently busy");
return i18n("The device is currently busy");
else if (error == UD2_ERROR_FAILED)
return QCoreApplication::translate("", "The requested operation has failed");
return i18n("The requested operation has failed");
else if (error == UD2_ERROR_CANCELED)
return QCoreApplication::translate("", "The requested operation has been canceled");
return i18n("The requested operation has been canceled");
else if (error == UD2_ERROR_INVALID_OPTION)
return QCoreApplication::translate("", "An invalid or malformed option has been given");
return i18n("An invalid or malformed option has been given");
else if (error == UD2_ERROR_MISSING_DRIVER)
return QCoreApplication::translate("", "The kernel driver for this filesystem type is not available");
return i18n("The kernel driver for this filesystem type is not available");
else if (error == UD2_ERROR_ALREADY_MOUNTED)
return QCoreApplication::translate("", "The device is already mounted");
return i18n("The device is already mounted");
else if (error == UD2_ERROR_NOT_MOUNTED)
return QCoreApplication::translate("", "The device is not mounted");
return i18n("The device is not mounted");
else if (error == UD2_ERROR_MOUNTED_BY_OTHER_USER)
return QCoreApplication::translate("", "The device is mounted by another user");
return i18n("The device is mounted by another user");
else if (error == UD2_ERROR_ALREADY_UNMOUNTING)
return QCoreApplication::translate("", "The device is already unmounting");
return i18n("The device is already unmounting");
else if (error == UD2_ERROR_TIMED_OUT)
return QCoreApplication::translate("", "The operation timed out");
return i18n("The operation timed out");
else if (error == UD2_ERROR_WOULD_WAKEUP)
return QCoreApplication::translate("", "The operation would wake up a disk that is in a deep-sleep state");
return i18n("The operation would wake up a disk that is in a deep-sleep state");
else if (error == UD2_ERROR_ALREADY_CANCELLED)
return QCoreApplication::translate("", "The operation has already been canceled");
return i18n("The operation has already been canceled");
else
return QCoreApplication::translate("", "An unspecified error has occurred");
return i18n("An unspecified error has occurred");
}
Solid::ErrorType Device::errorToSolidError(const QString & error) const

View file

@ -106,7 +106,7 @@ QString UPowerDevice::description() const
if (queryDeviceInterface(Solid::DeviceInterface::AcAdapter))
return QObject::tr("A/C Adapter");
else if (queryDeviceInterface(Solid::DeviceInterface::Battery))
return QObject::tr("%1 Battery", "%1 is battery technology").arg(batteryTechnology());
return QObject::tr("%1 Battery").arg(batteryTechnology());
else {
QString result = prop("Model").toString();
if (result.isEmpty()) {
@ -122,19 +122,19 @@ QString UPowerDevice::batteryTechnology() const
switch (tech)
{
case 1:
return QObject::tr("Lithium Ion", "battery technology");
return QObject::tr("Lithium Ion");
case 2:
return QObject::tr("Lithium Polymer", "battery technology");
return QObject::tr("Lithium Polymer");
case 3:
return QObject::tr("Lithium Iron Phosphate", "battery technology");
return QObject::tr("Lithium Iron Phosphate");
case 4:
return QObject::tr("Lead Acid", "battery technology");
return QObject::tr("Lead Acid");
case 5:
return QObject::tr("Nickel Cadmium", "battery technology");
return QObject::tr("Nickel Cadmium");
case 6:
return QObject::tr("Nickel Metal Hydride", "battery technology");
return QObject::tr("Nickel Metal Hydride");
default:
return QObject::tr("Unknown", "battery technology");
return QObject::tr("Unknown");
}
}

View file

@ -66,49 +66,49 @@ QString Solid::DeviceInterface::typeDescription(Type type)
switch (type)
{
case Unknown:
return QObject::tr("Unknown", "Unknown device type");
return QObject::tr("Unknown");
case GenericInterface:
return QObject::tr("Generic Interface", "Generic Interface device type");
return QObject::tr("Generic Interface");
case Processor:
return QObject::tr("Processor", "Processor device type");
return QObject::tr("Processor");
case Block:
return QObject::tr("Block", "Block device type");
return QObject::tr("Block");
case StorageAccess:
return QObject::tr("Storage Access", "Storage Access device type");
return QObject::tr("Storage Access");
case StorageDrive:
return QObject::tr("Storage Drive", "Storage Drive device type");
return QObject::tr("Storage Drive");
case OpticalDrive:
return QObject::tr("Optical Drive", "Optical Drive device type");
return QObject::tr("Optical Drive");
case StorageVolume:
return QObject::tr("Storage Volume", "Storage Volume device type");
return QObject::tr("Storage Volume");
case OpticalDisc:
return QObject::tr("Optical Disc", "Optical Disc device type");
return QObject::tr("Optical Disc");
case Camera:
return QObject::tr("Camera", "Camera device type");
return QObject::tr("Camera");
case PortableMediaPlayer:
return QObject::tr("Portable Media Player", "Portable Media Player device type");
return QObject::tr("Portable Media Player");
case NetworkInterface:
return QObject::tr("Network Interface", "Network Interface device type");
return QObject::tr("Network Interface");
case AcAdapter:
return QObject::tr("Ac Adapter", "Ac Adapter device type");
return QObject::tr("Ac Adapter");
case Battery:
return QObject::tr("Battery", "Battery device type");
return QObject::tr("Battery");
case Button:
return QObject::tr("Button", "Button device type");
return QObject::tr("Button");
case AudioInterface:
return QObject::tr("Audio Interface", "Audio Interface device type");
return QObject::tr("Audio Interface");
case DvbInterface:
return QObject::tr("Dvb Interface", "Dvb Interface device type");
return QObject::tr("Dvb Interface");
case Video:
return QObject::tr("Video", "Video device type");
return QObject::tr("Video");
case SerialInterface:
return QObject::tr("Serial Interface", "Serial Interface device type");
return QObject::tr("Serial Interface");
case SmartCardReader:
return QObject::tr("Smart Card Reader", "Smart Card Reader device type");
return QObject::tr("Smart Card Reader");
case InternetGateway:
return QObject::tr("Internet Gateway Device", "Internet Gateway device type");
return QObject::tr("Internet Gateway Device");
case NetworkShare:
return QObject::tr("Network Share", "Network Share device type");
return QObject::tr("Network Share");
case Last:
return QString();
}