Skip to content

Commit cf6fc66

Browse files
committedAug 23, 2012
Added translation to QgsMeasureDialog
1 parent 90d3ab6 commit cf6fc66

File tree

4 files changed

+7315
-3664
lines changed

4 files changed

+7315
-3664
lines changed
 

‎i18n/qgis_sv.ts

Lines changed: 7274 additions & 3589 deletions
Large diffs are not rendered by default.

‎src/app/qgsmeasuredialog.cpp

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -230,75 +230,40 @@ void QgsMeasureDialog::updateUi()
230230

231231
// Set tooltip to indicate how we calculate measurments
232232
QGis::UnitType mapUnits = mTool->canvas()->mapUnits();
233-
QString mapUnitsTxt;
234-
switch ( mapUnits )
235-
{
236-
case QGis::Meters:
237-
mapUnitsTxt = "meters";
238-
break;
239-
case QGis::Feet:
240-
mapUnitsTxt = "feet";
241-
break;
242-
case QGis::Degrees:
243-
mapUnitsTxt = "degrees";
244-
break;
245-
case QGis::UnknownUnit:
246-
mapUnitsTxt = "-";
247-
}
233+
QGis::UnitType displayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
248234

249-
QString toolTip = QString( "The calculations are based on:" );
235+
QString toolTip = tr( "The calculations are based on:" );
250236
if ( ! mTool->canvas()->hasCrsTransformEnabled() )
251237
{
252-
toolTip += QString( "%1 Project CRS transformation is turned off, canvas units setting" ).arg( "<br> *" );
253-
toolTip += QString( "is taken from project properties setting (%1)." ).arg( mapUnitsTxt );
254-
toolTip += QString( "%1 Ellipsoidal calculation is not possible, as project CRS is undefined." ).arg( "<br> *" );
238+
toolTip += "<br> * " + tr( "Project CRS transformation is turned off." ) + " ";
239+
toolTip += tr( "Canvas units setting is taken from project properties setting (%1)." ).arg( QGis::tr( mapUnits ) );
240+
toolTip += "<br> * " + tr( "Ellipsoidal calculation is not possible, as project CRS is undefined." );
255241
}
256242
else
257243
{
258244
if ( mDa.ellipsoidalEnabled() )
259245
{
260-
toolTip += QString( "%1 Project CRS transformation is turned on and ellipsoidal calculation is selected. " ).arg( "<br> *" );
261-
toolTip += QString( "The coordinates are transformed to the chosen ellipsoid (%1) and the result is in meters" ).arg( mDa.ellipsoid() );
246+
toolTip += "<br> * " + tr( "Project CRS transformation is turned on and ellipsoidal calculation is selected." ) + " ";
247+
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the result is in meters" ).arg( mDa.ellipsoid() );
262248
}
263249
else
264250
{
265-
toolTip += QString( "%1 Project CRS transformation is turned on but ellipsoidal calculation is not selected. " ).arg( "<br> *" );
266-
toolTip += QString( "The canvas units setting is taken from the project CRS (%1)." ).arg( mapUnitsTxt );
251+
toolTip += "<br> * " + tr( "Project CRS transformation is turned on but ellipsoidal calculation is not selected." ).arg( "<br> *" );
252+
toolTip += "<br> * " + tr( "The canvas units setting is taken from the project CRS (%1)." ).arg( QGis::tr( mapUnits ) );
267253
}
268254
}
269-
if ( mapUnits == QGis::Meters && settings.value( "/qgis/measure/displayunits", "meters" ).toString() == "feet" )
270-
{
271-
toolTip += QString( "%1 Finally, the value is converted from meters to feet." ).arg( "<br> *" );
272-
}
273-
else if ( mapUnits == QGis::Feet && settings.value( "/qgis/measure/displayunits", "meters" ).toString() == "meters" )
255+
256+
if (( mapUnits == QGis::Meters && displayUnits == QGis::Feet ) || ( mapUnits == QGis::Feet && displayUnits == QGis::Meters ) )
274257
{
275-
toolTip += QString( "%1 Finally, the value is converted from feet to meters." ).arg( "<br> *" );
258+
toolTip += "<br> * " + tr( "Finally, the value is converted from %2 to %3." ).arg( QGis::tr( mapUnits ) ).arg( QGis::tr( displayUnits ) );
276259
}
277260

278261
editTotal->setToolTip( toolTip );
279262
mTable->setToolTip( toolTip );
280263

281264
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
282265

283-
double dummy = 1.0;
284-
QGis::UnitType myDisplayUnits;
285-
// The dummy distance is ignored
286-
convertMeasurement( dummy, myDisplayUnits, false );
287-
288-
switch ( myDisplayUnits )
289-
{
290-
case QGis::Meters:
291-
mTable->setHeaderLabels( QStringList( tr( "Segments (in meters)" ) ) );
292-
break;
293-
case QGis::Feet:
294-
mTable->setHeaderLabels( QStringList( tr( "Segments (in feet)" ) ) );
295-
break;
296-
case QGis::Degrees:
297-
mTable->setHeaderLabels( QStringList( tr( "Segments (in degrees)" ) ) );
298-
break;
299-
case QGis::UnknownUnit:
300-
mTable->setHeaderLabels( QStringList( tr( "Segments" ) ) );
301-
}
266+
mTable->setHeaderLabels( QStringList( tr( "Segments [%1]" ).arg( QGis::tr( displayUnits ) ) ) );
302267

303268
if ( mMeasureArea )
304269
{
@@ -322,18 +287,9 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b
322287

323288
// Get the units for display
324289
QSettings settings;
325-
QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
326-
QgsDebugMsg( QString( "Preferred display units are %1" ).arg( myDisplayUnitsTxt ) );
290+
QGis::UnitType displayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
327291

328-
QGis::UnitType displayUnits;
329-
if ( myDisplayUnitsTxt == "feet" )
330-
{
331-
displayUnits = QGis::Feet;
332-
}
333-
else
334-
{
335-
displayUnits = QGis::Meters;
336-
}
292+
QgsDebugMsg( QString( "Preferred display units are %1" ).arg( QGis::toLiteral( displayUnits ) ) );
337293

338294
mDa.convertMeasurement( measure, myUnits, displayUnits, isArea );
339295
u = myUnits;

‎src/core/qgis.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef QGSVERSION
2020
#include "qgsversion.h"
2121
#endif
22-
22+
#include <QCoreApplication>
2323
#include "qgsconfig.h"
2424

2525
#include <ogr_api.h>
@@ -74,28 +74,33 @@ const double QGis::DEFAULT_IDENTIFY_RADIUS = 0.5;
7474
// Order must match enum indices
7575
const char* QGis::qgisUnitTypes[] =
7676
{
77-
"meters",
78-
"feet",
79-
"degrees",
80-
"<unknown>",
81-
"degrees",
82-
"degrees",
83-
"degrees"
77+
QT_TRANSLATE_NOOP( "QGis::UnitType", "meters" ),
78+
QT_TRANSLATE_NOOP( "QGis::UnitType", "feet" ),
79+
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
80+
QT_TRANSLATE_NOOP( "QGis::UnitType", "<unknown>" ),
81+
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
82+
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
83+
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" )
8484
};
8585

86-
QGis::UnitType QGis::fromString( QString unitTxt, QGis::UnitType defaultType )
86+
QGis::UnitType QGis::fromLiteral( QString literal, QGis::UnitType defaultType )
8787
{
88-
for ( int i = 0; i < sizeof( qgisUnitTypes ); i++ )
88+
for ( unsigned int i = 0; i < sizeof( qgisUnitTypes ); i++ )
8989
{
90-
if ( unitTxt == qgisUnitTypes[ i ] )
90+
if ( literal == qgisUnitTypes[ i ] )
9191
{
9292
return static_cast<UnitType>( i );
9393
}
9494
}
9595
return defaultType;
9696
}
9797

98-
QString QGis::toString( QGis::UnitType unit )
98+
QString QGis::toLiteral( QGis::UnitType unit )
99+
{
100+
return QString( qgisUnitTypes[ static_cast<int>( unit )] );
101+
}
102+
103+
QString QGis::tr( QGis::UnitType unit )
99104
{
100-
return QString( qgisUnitTypes[ static_cast<int>( unit ) ] );
105+
return QCoreApplication::translate( "QGis::UnitType", qPrintable( toLiteral( unit ) ) );
101106
}

‎src/core/qgis.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <QEvent>
2222
#include <QString>
23+
#include <QMetaType>
2324
#include <cfloat>
2425
#include <cmath>
2526
#include <qnumeric.h>
@@ -95,9 +96,13 @@ class CORE_EXPORT QGis
9596
DegreesMinutesSeconds = 2, // was 4
9697
DegreesDecimalMinutes = 2, // was 5
9798
};
98-
// Converters for the above type
99-
static QString toString( QGis::UnitType unit );
100-
static UnitType fromString( QString unitTxt, QGis::UnitType defaultType = UnknownUnit );
99+
100+
// Provides the canonical name of the type value
101+
static QString toLiteral( QGis::UnitType unit );
102+
// Converts from the canonical name to the type value
103+
static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
104+
// Provides translated version of the type value
105+
static QString tr( QGis::UnitType unit );
101106

102107
//! User defined event types
103108
enum UserEvent

0 commit comments

Comments
 (0)
Please sign in to comment.