Skip to content

Commit 4fe3887

Browse files
authoredDec 25, 2018
Merge pull request #8740 from DelazJ/translateExpr
Expression parser fixes [Backport]
2 parents 91adb60 + ea43838 commit 4fe3887

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed
 

‎scripts/update_ts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ files=
7979
if [ -d "$2" ]; then
8080
builddir=$(realpath $2)
8181
textcpp=
82-
for i in $builddir/src/core/qgsexpression_texts.cpp; do
82+
for i in $builddir/src/core/qgsexpression_texts.cpp $builddir/src/core/qgsexpressionparser.cpp; do
8383
if [ -f $i ]; then
8484
textcpp="$textcpp $i"
8585
elif [ "$action" != "pull" ]; then

‎scripts/update_ts_files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ done
126126
echo Updating GRASS module translations
127127
perl scripts/qgm2cpp.pl >src/plugins/grass/grasslabels-i18n.cpp
128128
echo Creating qmake project file
129-
$QMAKE -project -o qgis_ts.pro -nopwd src python i18n "$builddir/src/core/qgsexpression_texts.cpp"
129+
$QMAKE -project -o qgis_ts.pro -nopwd src python i18n "$builddir/src/core/qgsexpression_texts.cpp" "$builddir/src/core/qgsexpressionparser.cpp"
130130
if [ -n "$add" ]; then
131131
for i in $add; do
132132
echo "Adding translation for $i"

‎src/core/qgsexpressionparser.yy

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ expression:
217217
{
218218
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
219219
parser_ctx->currentErrorType = errorType;
220-
exp_error(&yyloc, parser_ctx, "Function is not known");
220+
exp_error(&yyloc, parser_ctx, QObject::tr( "Function is not known" ).toUtf8().constData() );
221221
delete $3;
222222
YYERROR;
223223
}
@@ -238,21 +238,19 @@ expression:
238238
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs;
239239
parser_ctx->currentErrorType = errorType;
240240
QString expectedMessage;
241-
if (func->params() == func->minParams())
241+
if ( func->params() == func->minParams() )
242242
{
243-
expectedMessage = QString("Expected %2" ).arg( func->params());
243+
expectedMessage = QObject::tr( "Expected %1 but got %2." ).arg( QString::number( func->params() ), QString::number( $3->count() ) );
244244
}
245245
else
246246
{
247-
expectedMessage = QString("Expected between %2 and %4 max but got %3" ).arg( func->minParams(), func->params() );
247+
expectedMessage = QObject::tr( "Expected between %1 and %2 parameters but %3 were provided." ).arg( QString::number( func->minParams() ), QString::number( func->params() ), QString::number( $3->count() ) );
248248
}
249-
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments."
250-
"%2 but got %3" ).arg( QgsExpression::Functions()[fnIndex]->name() )
251-
.arg( expectedMessage )
252-
.arg( $3->count() ).toLocal8Bit().constData() );
249+
exp_error(&yyloc, parser_ctx, QObject::tr( "%1 function is called with wrong number of arguments. %2" ).arg( QgsExpression::Functions()[fnIndex]->name(), expectedMessage ).toUtf8().constData() );
253250
delete $3;
254251
YYERROR;
255252
}
253+
256254
$$ = new QgsExpressionNodeFunction(fnIndex, $3);
257255
addParserLocation(&@1, $$);
258256
}
@@ -265,7 +263,7 @@ expression:
265263
{
266264
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
267265
parser_ctx->currentErrorType = errorType;
268-
exp_error(&yyloc, parser_ctx, "Function is not known");
266+
exp_error(&yyloc, parser_ctx, QObject::tr( "Function is not known" ).toUtf8().constData() );
269267
YYERROR;
270268
}
271269
// 0 parameters is expected, -1 parameters means leave it to the
@@ -274,7 +272,7 @@ expression:
274272
{
275273
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs;
276274
parser_ctx->currentErrorType = errorType;
277-
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments" ).arg( QgsExpression::Functions()[fnIndex]->name() ).toLocal8Bit().constData() );
275+
exp_error(&yyloc, parser_ctx, QObject::tr( "%1 function is called with wrong number of arguments" ).arg( QgsExpression::Functions()[fnIndex]->name() ).toLocal8Bit().constData() );
278276
YYERROR;
279277
}
280278
$$ = new QgsExpressionNodeFunction(fnIndex, new QgsExpressionNode::NodeList());
@@ -306,7 +304,7 @@ expression:
306304
{
307305
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
308306
parser_ctx->currentErrorType = errorType;
309-
exp_error(&yyloc, parser_ctx, QString("%1 function is not known").arg(*$1).toLocal8Bit().constData());
307+
exp_error(&yyloc, parser_ctx, QObject::tr( "%1 function is not known" ).arg( *$1 ).toLocal8Bit().constData());
310308
YYERROR;
311309
}
312310
delete $1;
@@ -317,7 +315,7 @@ expression:
317315
{
318316
// @var is equivalent to var( "var" )
319317
QgsExpressionNode::NodeList* args = new QgsExpressionNode::NodeList();
320-
QgsExpressionNodeLiteral* literal = new QgsExpressionNodeLiteral( QString(*$1).mid(1) );
318+
QgsExpressionNodeLiteral* literal = new QgsExpressionNodeLiteral( QString( *$1 ).mid( 1 ) );
321319
args->append( literal );
322320
$$ = new QgsExpressionNodeFunction( QgsExpression::functionIndex( "var" ), args );
323321
delete $1;
@@ -342,7 +340,7 @@ exp_list:
342340
{
343341
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionNamedArgsError;
344342
parser_ctx->currentErrorType = errorType;
345-
exp_error(&yyloc, parser_ctx, "All parameters following a named parameter must also be named.");
343+
exp_error(&yyloc, parser_ctx, QObject::tr( "All parameters following a named parameter must also be named." ).toUtf8().constData() );
346344
delete $1;
347345
YYERROR;
348346
}

0 commit comments

Comments
 (0)
Please sign in to comment.