Next step towards working translations

This may seem like a really odd change - but with this change the Qt tools
can correctly parse the C files (and qt-gui.cpp) and get the context for
the translatable strings right.

It's not super-pretty (I'll admit that _("string literal") is much easier
on the eye than translate("gettextFromC", "string literal") ) but I think
this will be the price of success.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-10-09 22:48:35 -07:00
parent 2d69d4a5ef
commit 193d20c479
14 changed files with 184 additions and 182 deletions

View file

@ -39,7 +39,9 @@
#include <QLibraryInfo>
#include <gettextfromc.h>
#define tr(arg) gettextFromC::instance()->tr(arg)
// this will create a warning when executing lupdate
#define translate(_context, arg) gettextFromC::instance()->tr("gettextFromC",arg)
const char *default_dive_computer_vendor;
const char *default_dive_computer_product;
@ -192,10 +194,10 @@ QString get_depth_string(int mm, bool showunit, bool showdecimal)
{
if (prefs.units.length == units::METERS) {
double meters = mm / 1000.0;
return QString("%1%2").arg(meters, 0, 'f', (showdecimal && meters < 20.0) ? 1 : 0 ).arg(showunit ? tr("m") : "");
return QString("%1%2").arg(meters, 0, 'f', (showdecimal && meters < 20.0) ? 1 : 0 ).arg(showunit ? translate("gettextFromC","m") : "");
} else {
double feet = mm_to_feet(mm);
return QString("%1%2").arg(feet, 0, 'f', showdecimal ? 1 : 0). arg(showunit ? tr("ft") : "");
return QString("%1%2").arg(feet, 0, 'f', showdecimal ? 1 : 0). arg(showunit ? translate("gettextFromC","ft") : "");
}
}
@ -216,9 +218,9 @@ QString get_weight_string(weight_t weight, bool showunit)
{
QString str = weight_string (weight.grams);
if (get_units()->weight == units::KG) {
str = QString ("%1%2").arg(str).arg(showunit ? tr("kg") : "");
str = QString ("%1%2").arg(str).arg(showunit ? translate("gettextFromC","kg") : "");
} else {
str = QString ("%1%2").arg(str).arg(showunit ? tr("lbs") : "");
str = QString ("%1%2").arg(str).arg(showunit ? translate("gettextFromC","lbs") : "");
}
return (str);
}
@ -258,7 +260,7 @@ QString get_cylinder_used_gas_string(cylinder_t *cyl, bool showunit)
gas_usage = get_pressure_units(gas_usage, &unit);
decimals = 0;
}
// tr("%.*f %s"
// translate("gettextFromC","%.*f %s"
return QString("%1 %2").arg(gas_usage, 0, 'f', decimals).arg(showunit ? unit : "");
}
@ -269,11 +271,11 @@ QString get_temperature_string(temperature_t temp, bool showunit)
} else if (prefs.units.temperature == units::CELSIUS) {
double celsius = mkelvin_to_C(temp.mkelvin);
return QString("%1%2%3").arg(celsius, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE): "")
.arg(showunit ? tr("C") : "");
.arg(showunit ? translate("gettextFromC","C") : "");
} else {
double fahrenheit = mkelvin_to_F(temp.mkelvin);
return QString("%1%2%3").arg(fahrenheit, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE): "")
.arg(showunit ? tr("F") : "");
.arg(showunit ? translate("gettextFromC","F") : "");
}
}
@ -289,10 +291,10 @@ QString get_volume_string(volume_t volume, bool showunit)
{
if (prefs.units.volume == units::LITER) {
double liter = volume.mliter / 1000.0;
return QString("%1%2").arg(liter, 0, 'f', liter >= 40.0 ? 0 : 1 ).arg(showunit ? tr("l") : "");
return QString("%1%2").arg(liter, 0, 'f', liter >= 40.0 ? 0 : 1 ).arg(showunit ? translate("gettextFromC","l") : "");
} else {
double cuft = ml_to_cuft(volume.mliter);
return QString("%1%2").arg(cuft, 0, 'f', cuft >= 20.0 ? 0 : (cuft >= 2.0 ? 1 : 2)).arg(showunit ? tr("cuft") : "");
return QString("%1%2").arg(cuft, 0, 'f', cuft >= 20.0 ? 0 : (cuft >= 2.0 ? 1 : 2)).arg(showunit ? translate("gettextFromC","cuft") : "");
}
}
@ -308,10 +310,10 @@ QString get_pressure_string(pressure_t pressure, bool showunit)
{
if (prefs.units.pressure == units::BAR) {
double bar = pressure.mbar / 1000.0;
return QString("%1%2").arg(bar, 0, 'f', 1).arg(showunit ? tr("bar") : "");
return QString("%1%2").arg(bar, 0, 'f', 1).arg(showunit ? translate("gettextFromC","bar") : "");
} else {
double psi = mbar_to_PSI(pressure.mbar);
return QString("%1%2").arg(psi, 0, 'f', 0).arg(showunit ? tr("psi") : "");
return QString("%1%2").arg(psi, 0, 'f', 0).arg(showunit ? translate("gettextFromC","psi") : "");
}
}