Translations: unify gettextFromC::tr() and QObject::tr()

There were two catch-all classes for translations outside of class
context. gettextFromC was used exclusively from C, but C++ used
both, gettextFromC and QObject. Some of the string were even present
in both. Therefore, unify to gettextFromC throughout the code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-07-03 16:52:20 +02:00 committed by Dirk Hohndel
parent 2f95141330
commit 57c01f7a66
11 changed files with 41 additions and 39 deletions

View file

@ -53,7 +53,7 @@ static void exportHTMLstatisticsTotal(QTextStream &out, stats_t *total_stats)
out << "\"YEAR\":\"Total\","; out << "\"YEAR\":\"Total\",";
out << "\"DIVES\":\"" << total_stats->selection_size << "\","; out << "\"DIVES\":\"" << total_stats->selection_size << "\",";
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(total_stats->total_time.seconds, out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(total_stats->total_time.seconds,
QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\","; gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\",";
out << "\"AVERAGE_TIME\":\"--\","; out << "\"AVERAGE_TIME\":\"--\",";
out << "\"SHORTEST_TIME\":\"--\","; out << "\"SHORTEST_TIME\":\"--\",";
out << "\"LONGEST_TIME\":\"--\","; out << "\"LONGEST_TIME\":\"--\",";
@ -89,7 +89,7 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin
out << "\"YEAR\":\"" << stats_yearly[i].period << "\","; out << "\"YEAR\":\"" << stats_yearly[i].period << "\",";
out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\","; out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\",";
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats_yearly[i].total_time.seconds, out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats_yearly[i].total_time.seconds,
QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\","; gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\",";
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\","; out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\",";
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\","; out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\",";
out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\","; out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\",";

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "divesite.h" #include "divesite.h"
#include "pref.h" #include "pref.h"
#include "gettextfromc.h"
QString constructLocationTags(struct dive_site *ds, bool for_maintab) QString constructLocationTags(struct dive_site *ds, bool for_maintab)
{ {
@ -17,7 +18,7 @@ QString constructLocationTags(struct dive_site *ds, bool for_maintab)
} }
if (!prefs_set && !for_maintab) { if (!prefs_set && !for_maintab) {
locationTag = QString("<small><small>") + QObject::tr("No dive site layout categories set in preferences!") + locationTag = QString("<small><small>") + gettextFromC::tr("No dive site layout categories set in preferences!") +
QString("</small></small>"); QString("</small></small>");
return locationTag; return locationTag;
} }
@ -25,7 +26,7 @@ QString constructLocationTags(struct dive_site *ds, bool for_maintab)
return locationTag; return locationTag;
if (for_maintab) if (for_maintab)
locationTag = QString("<small><small>(") + QObject::tr("Tags") + QString(": "); locationTag = QString("<small><small>(") + gettextFromC::tr("Tags") + QString(": ");
else else
locationTag = QString("<small><small>"); locationTag = QString("<small><small>");
QString connector; QString connector;

View file

@ -11,7 +11,7 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QMap> #include <QMap>
#define GPS_CURRENT_POS QObject::tr("Waiting to aquire GPS location") #define GPS_CURRENT_POS gettextFromC::tr("Waiting to aquire GPS location")
struct gpsTracker { struct gpsTracker {
degrees_t latitude; degrees_t latitude;

View file

@ -762,9 +762,9 @@ int parseLengthToMm(const QString &text)
if (numOnly.isEmpty()) if (numOnly.isEmpty())
return 0; return 0;
double number = numOnly.toDouble(); double number = numOnly.toDouble();
if (text.contains(QObject::tr("m"), Qt::CaseInsensitive)) { if (text.contains(gettextFromC::tr("m"), Qt::CaseInsensitive)) {
mm = lrint(number * 1000); mm = lrint(number * 1000);
} else if (text.contains(QObject::tr("ft"), Qt::CaseInsensitive)) { } else if (text.contains(gettextFromC::tr("ft"), Qt::CaseInsensitive)) {
mm = feet_to_mm(number); mm = feet_to_mm(number);
} else { } else {
switch (prefs.units.length) { switch (prefs.units.length) {
@ -790,9 +790,9 @@ int parseTemperatureToMkelvin(const QString &text)
if (numOnly.isEmpty()) if (numOnly.isEmpty())
return 0; return 0;
double number = numOnly.toDouble(); double number = numOnly.toDouble();
if (text.contains(QObject::tr("C"), Qt::CaseInsensitive)) { if (text.contains(gettextFromC::tr("C"), Qt::CaseInsensitive)) {
mkelvin = C_to_mkelvin(number); mkelvin = C_to_mkelvin(number);
} else if (text.contains(QObject::tr("F"), Qt::CaseInsensitive)) { } else if (text.contains(gettextFromC::tr("F"), Qt::CaseInsensitive)) {
mkelvin = F_to_mkelvin(number); mkelvin = F_to_mkelvin(number);
} else { } else {
switch (prefs.units.temperature) { switch (prefs.units.temperature) {
@ -817,9 +817,9 @@ int parseWeightToGrams(const QString &text)
if (numOnly.isEmpty()) if (numOnly.isEmpty())
return 0; return 0;
double number = numOnly.toDouble(); double number = numOnly.toDouble();
if (text.contains(QObject::tr("kg"), Qt::CaseInsensitive)) { if (text.contains(gettextFromC::tr("kg"), Qt::CaseInsensitive)) {
grams = lrint(number * 1000); grams = lrint(number * 1000);
} else if (text.contains(QObject::tr("lbs"), Qt::CaseInsensitive)) { } else if (text.contains(gettextFromC::tr("lbs"), Qt::CaseInsensitive)) {
grams = lbs_to_grams(number); grams = lbs_to_grams(number);
} else { } else {
switch (prefs.units.weight) { switch (prefs.units.weight) {
@ -844,9 +844,9 @@ int parsePressureToMbar(const QString &text)
if (numOnly.isEmpty()) if (numOnly.isEmpty())
return 0; return 0;
double number = numOnly.toDouble(); double number = numOnly.toDouble();
if (text.contains(QObject::tr("bar"), Qt::CaseInsensitive)) { if (text.contains(gettextFromC::tr("bar"), Qt::CaseInsensitive)) {
mbar = lrint(number * 1000); mbar = lrint(number * 1000);
} else if (text.contains(QObject::tr("psi"), Qt::CaseInsensitive)) { } else if (text.contains(gettextFromC::tr("psi"), Qt::CaseInsensitive)) {
mbar = psi_to_mbar(number); mbar = psi_to_mbar(number);
} else { } else {
switch (prefs.units.pressure) { switch (prefs.units.pressure) {
@ -867,9 +867,9 @@ int parseGasMixO2(const QString &text)
{ {
QString gasString = text; QString gasString = text;
int o2, number; int o2, number;
if (gasString.contains(QObject::tr("AIR"), Qt::CaseInsensitive)) { if (gasString.contains(gettextFromC::tr("AIR"), Qt::CaseInsensitive)) {
o2 = O2_IN_AIR; o2 = O2_IN_AIR;
} else if (gasString.contains(QObject::tr("EAN"), Qt::CaseInsensitive)) { } else if (gasString.contains(gettextFromC::tr("EAN"), Qt::CaseInsensitive)) {
gasString.remove(QRegExp("[^0-9]")); gasString.remove(QRegExp("[^0-9]"));
number = gasString.toInt(); number = gasString.toInt();
o2 = number * 10; o2 = number * 10;
@ -1007,7 +1007,7 @@ QString get_trip_date_string(timestamp_t when, int nr, bool getday)
localTime.setTimeSpec(Qt::UTC); localTime.setTimeSpec(Qt::UTC);
QString ret ; QString ret ;
QString suffix = " " + QObject::tr("(%n dive(s))", "", nr); QString suffix = " " + gettextFromC::tr("(%n dive(s))", "", nr);
if (getday) { if (getday) {
ret = localTime.date().toString(prefs.date_format) + suffix; ret = localTime.date().toString(prefs.date_format) + suffix;
} else { } else {
@ -1235,7 +1235,7 @@ extern "C" char *picturedir_string()
QString get_gas_string(struct gasmix gas) QString get_gas_string(struct gasmix gas)
{ {
uint o2 = (get_o2(&gas) + 5) / 10, he = (get_he(&gas) + 5) / 10; uint o2 = (get_o2(&gas) + 5) / 10, he = (get_he(&gas) + 5) / 10;
QString result = gasmix_is_air(&gas) ? QObject::tr("AIR") : he == 0 ? (o2 == 100 ? QObject::tr("OXYGEN") : QString("EAN%1").arg(o2, 2, 10, QChar('0'))) : QString("%1/%2").arg(o2).arg(he); QString result = gasmix_is_air(&gas) ? gettextFromC::tr("AIR") : he == 0 ? (o2 == 100 ? gettextFromC::tr("OXYGEN") : QString("EAN%1").arg(o2, 2, 10, QChar('0'))) : QString("%1/%2").arg(o2).arg(he);
return result; return result;
} }
@ -1258,8 +1258,8 @@ weight_t string_to_weight(const char *str)
const char *end; const char *end;
double value = strtod_flags(str, &end, 0); double value = strtod_flags(str, &end, 0);
QString rest = QString(end).trimmed(); QString rest = QString(end).trimmed();
QString local_kg = QObject::tr("kg"); QString local_kg = gettextFromC::tr("kg");
QString local_lbs = QObject::tr("lbs"); QString local_lbs = gettextFromC::tr("lbs");
weight_t weight; weight_t weight;
if (rest.startsWith("kg") || rest.startsWith(local_kg)) if (rest.startsWith("kg") || rest.startsWith(local_kg))
@ -1282,8 +1282,8 @@ depth_t string_to_depth(const char *str)
const char *end; const char *end;
double value = strtod_flags(str, &end, 0); double value = strtod_flags(str, &end, 0);
QString rest = QString(end).trimmed(); QString rest = QString(end).trimmed();
QString local_ft = QObject::tr("ft"); QString local_ft = gettextFromC::tr("ft");
QString local_m = QObject::tr("m"); QString local_m = gettextFromC::tr("m");
depth_t depth; depth_t depth;
if (value < 0) if (value < 0)
@ -1307,8 +1307,8 @@ pressure_t string_to_pressure(const char *str)
const char *end; const char *end;
double value = strtod_flags(str, &end, 0); double value = strtod_flags(str, &end, 0);
QString rest = QString(end).trimmed(); QString rest = QString(end).trimmed();
QString local_psi = QObject::tr("psi"); QString local_psi = gettextFromC::tr("psi");
QString local_bar = QObject::tr("bar"); QString local_bar = gettextFromC::tr("bar");
pressure_t pressure; pressure_t pressure;
if (rest.startsWith("bar") || rest.startsWith(local_bar)) if (rest.startsWith("bar") || rest.startsWith(local_bar))
@ -1330,8 +1330,8 @@ volume_t string_to_volume(const char *str, pressure_t workp)
const char *end; const char *end;
double value = strtod_flags(str, &end, 0); double value = strtod_flags(str, &end, 0);
QString rest = QString(end).trimmed(); QString rest = QString(end).trimmed();
QString local_l = QObject::tr("l"); QString local_l = gettextFromC::tr("l");
QString local_cuft = QObject::tr("cuft"); QString local_cuft = gettextFromC::tr("cuft");
volume_t volume; volume_t volume;
if (rest.startsWith("l") || rest.startsWith("") || rest.startsWith(local_l)) if (rest.startsWith("l") || rest.startsWith("") || rest.startsWith(local_l))

View file

@ -18,6 +18,7 @@ enum inertgas {N2, HE};
#include <QString> #include <QString>
#include <QTranslator> #include <QTranslator>
#include <QDir> #include <QDir>
#include "core/gettextfromc.h"
QString weight_string(int weight_in_grams); QString weight_string(int weight_in_grams);
QString distance_string(int distanceInMeters); QString distance_string(int distanceInMeters);
bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_text, bool *parsed_out = 0); bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_text, bool *parsed_out = 0);
@ -69,7 +70,7 @@ int parsePressureToMbar(const QString &text);
int parseGasMixO2(const QString &text); int parseGasMixO2(const QString &text);
int parseGasMixHE(const QString &text); int parseGasMixHE(const QString &text);
QString render_seconds_to_string(int seconds); QString render_seconds_to_string(int seconds);
QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText = QObject::tr("sec"), QString separator = ":", bool isFreeDive = false); QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText = gettextFromC::tr("sec"), QString separator = ":", bool isFreeDive = false);
QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator = " ", int maxdays = 4); QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator = " ", int maxdays = 4);
QString get_dive_date_string(timestamp_t when); QString get_dive_date_string(timestamp_t when);
QString get_short_dive_date_string(timestamp_t when); QString get_short_dive_date_string(timestamp_t when);

View file

@ -27,7 +27,7 @@ static QString getFormattedCylinder(struct dive *dive, unsigned int idx)
const char *desc = cyl->type.description; const char *desc = cyl->type.description;
if (!desc && idx > 0) if (!desc && idx > 0)
return QString(EMPTY_DIVE_STRING); return QString(EMPTY_DIVE_STRING);
QString fmt = desc ? QString(desc) : QObject::tr("unknown"); QString fmt = desc ? QString(desc) : gettextFromC::tr("unknown");
fmt += ", " + get_volume_string(cyl->type.size, true); fmt += ", " + get_volume_string(cyl->type.size, true);
fmt += ", " + get_pressure_string(cyl->type.workingpressure, true); fmt += ", " + get_pressure_string(cyl->type.workingpressure, true);
fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true); fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true);
@ -129,7 +129,7 @@ QVariant DiveObjectHelper::dive_site_uuid() const
QString DiveObjectHelper::duration() const QString DiveObjectHelper::duration() const
{ {
return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h"), QObject::tr("min")); return get_dive_duration_string(m_dive->duration.seconds, gettextFromC::tr("h"), gettextFromC::tr("min"));
} }
bool DiveObjectHelper::noDive() const bool DiveObjectHelper::noDive() const

View file

@ -62,7 +62,7 @@ void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
// don't allow removing the last point // don't allow removing the last point
if (plannerModel->rowCount() > 1) { if (plannerModel->rowCount() > 1) {
m.addSeparator(); m.addSeparator();
m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove())); m.addAction(gettextFromC::tr("Remove this point"), this, SLOT(selfRemove()));
m.exec(event->screenPos()); m.exec(event->screenPos());
} }
} }

View file

@ -635,7 +635,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
static bool saveToCloudOK() static bool saveToCloudOK()
{ {
if (!dive_table.nr) { if (!dive_table.nr) {
report_error(qPrintable(QObject::tr("Don't save an empty log to the cloud"))); report_error(qPrintable(gettextFromC::tr("Don't save an empty log to the cloud")));
return false; return false;
} }
return true; return true;

View file

@ -31,13 +31,13 @@ public:
{ {
avgIco = new QLabel(owner); avgIco = new QLabel(owner);
avgIco->setPixmap(QIcon(":value-average-icon").pixmap(16, 16)); avgIco->setPixmap(QIcon(":value-average-icon").pixmap(16, 16));
avgIco->setToolTip(QObject::tr("Average")); avgIco->setToolTip(gettextFromC::tr("Average"));
minIco = new QLabel(owner); minIco = new QLabel(owner);
minIco->setPixmap(QIcon(":value-minimum-icon").pixmap(16, 16)); minIco->setPixmap(QIcon(":value-minimum-icon").pixmap(16, 16));
minIco->setToolTip(QObject::tr("Minimum")); minIco->setToolTip(gettextFromC::tr("Minimum"));
maxIco = new QLabel(owner); maxIco = new QLabel(owner);
maxIco->setPixmap(QIcon(":value-maximum-icon").pixmap(16, 16)); maxIco->setPixmap(QIcon(":value-maximum-icon").pixmap(16, 16));
maxIco->setToolTip(QObject::tr("Maximum")); maxIco->setToolTip(gettextFromC::tr("Maximum"));
avgValue = new QLabel(owner); avgValue = new QLabel(owner);
minValue = new QLabel(owner); minValue = new QLabel(owner);
maxValue = new QLabel(owner); maxValue = new QLabel(owner);

View file

@ -620,7 +620,7 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData)
* </DiveDateReader> * </DiveDateReader>
*/ */
QXmlStreamReader reader(xmlData); QXmlStreamReader reader(xmlData);
const QString invalidXmlError = QObject::tr("Invalid response from server"); const QString invalidXmlError = gettextFromC::tr("Invalid response from server");
bool seenDiveDates = false; bool seenDiveDates = false;
DiveListResult result; DiveListResult result;
result.idCount = 0; result.idCount = 0;
@ -628,7 +628,7 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData)
if (reader.readNextStartElement() && reader.name() != "DiveDateReader") { if (reader.readNextStartElement() && reader.name() != "DiveDateReader") {
result.errorCondition = invalidXmlError; result.errorCondition = invalidXmlError;
result.errorDetails = result.errorDetails =
QObject::tr("Expected XML tag 'DiveDateReader', got instead '%1") gettextFromC::tr("Expected XML tag 'DiveDateReader', got instead '%1")
.arg(reader.name().toString()); .arg(reader.name().toString());
goto out; goto out;
} }
@ -674,14 +674,14 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData)
if (!seenDiveDates) { if (!seenDiveDates) {
result.errorCondition = invalidXmlError; result.errorCondition = invalidXmlError;
result.errorDetails = QObject::tr("Expected XML tag 'DiveDates' not found"); result.errorDetails = gettextFromC::tr("Expected XML tag 'DiveDates' not found");
} }
out: out:
if (reader.hasError()) { if (reader.hasError()) {
// if there was an XML error, overwrite the result or other error conditions // if there was an XML error, overwrite the result or other error conditions
result.errorCondition = invalidXmlError; result.errorCondition = invalidXmlError;
result.errorDetails = QObject::tr("Malformed XML response. Line %1: %2") result.errorDetails = gettextFromC::tr("Malformed XML response. Line %1: %2")
.arg(reader.lineNumber()) .arg(reader.lineNumber())
.arg(reader.errorString()); .arg(reader.errorString());
} }

View file

@ -107,8 +107,8 @@ if (property == "year") {
} else if (property == "max_temp") { } else if (property == "max_temp") {
return object.year->max_temp.mkelvin == 0 ? "0" : get_temperature_string(object.year->max_temp, true); return object.year->max_temp.mkelvin == 0 ? "0" : get_temperature_string(object.year->max_temp, true);
} else if (property == "total_time") { } else if (property == "total_time") {
return get_dive_duration_string(object.year->total_time.seconds, QObject::tr("h"), return get_dive_duration_string(object.year->total_time.seconds, gettextFromC::tr("h"),
QObject::tr("min"), QObject::tr("sec"), " "); gettextFromC::tr("min"), gettextFromC::tr("sec"), " ");
} else if (property == "avg_time") { } else if (property == "avg_time") {
return get_minutes(object.year->total_time.seconds / object.year->selection_size); return get_minutes(object.year->total_time.seconds / object.year->selection_size);
} else if (property == "shortest_time") { } else if (property == "shortest_time") {