Skip to content

Commit 3dd3609

Browse files
authored
Merge pull request #8720 from m-kuhn/expression_parser_error_fix
Make expression parser output translatable
2 parents 055a166 + 1f3cbb4 commit 3dd3609

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ expression:
218218
{
219219
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
220220
parser_ctx->currentErrorType = errorType;
221-
exp_error(&yyloc, parser_ctx, "Function is not known");
221+
exp_error(&yyloc, parser_ctx, QObject::tr( "Function is not known" ).toUtf8().constData() );
222222
delete $3;
223223
YYERROR;
224224
}
@@ -241,13 +241,13 @@ expression:
241241
QString expectedMessage;
242242
if ( func->params() == func->minParams() )
243243
{
244-
expectedMessage = QStringLiteral( "Expected %1 but got %2." ).arg( QString::number( func->params() ), QString::number( $3->count() ) );
244+
expectedMessage = QObject::tr( "Expected %1 but got %2." ).arg( QString::number( func->params() ), QString::number( $3->count() ) );
245245
}
246246
else
247247
{
248-
expectedMessage = QStringLiteral( "Expected between %1 and %2 parameters but %3 were provided." ).arg( QString::number( func->minParams() ), QString::number( func->params() ), QString::number( $3->count() ) );
248+
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() ) );
249249
}
250-
exp_error(&yyloc, parser_ctx, QStringLiteral( "%1 function is called with wrong number of arguments. %2" ).arg( QgsExpression::Functions()[fnIndex]->name(), expectedMessage ).toUtf8().constData() );
250+
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() );
251251
delete $3;
252252
YYERROR;
253253
}
@@ -264,7 +264,7 @@ expression:
264264
{
265265
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
266266
parser_ctx->currentErrorType = errorType;
267-
exp_error(&yyloc, parser_ctx, "Function is not known");
267+
exp_error(&yyloc, parser_ctx, QObject::tr( "Function is not known" ).toUtf8().constData() );
268268
YYERROR;
269269
}
270270
// 0 parameters is expected, -1 parameters means leave it to the
@@ -273,7 +273,7 @@ expression:
273273
{
274274
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs;
275275
parser_ctx->currentErrorType = errorType;
276-
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments" ).arg( QgsExpression::Functions()[fnIndex]->name() ).toLocal8Bit().constData() );
276+
exp_error(&yyloc, parser_ctx, QObject::tr( "%1 function is called with wrong number of arguments" ).arg( QgsExpression::Functions()[fnIndex]->name() ).toLocal8Bit().constData() );
277277
YYERROR;
278278
}
279279
$$ = new QgsExpressionNodeFunction(fnIndex, new QgsExpressionNode::NodeList());
@@ -307,7 +307,7 @@ expression:
307307
{
308308
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
309309
parser_ctx->currentErrorType = errorType;
310-
exp_error(&yyloc, parser_ctx, QString("%1 function is not known").arg(*$1).toLocal8Bit().constData());
310+
exp_error(&yyloc, parser_ctx, QObject::tr( "%1 function is not known" ).arg( *$1 ).toLocal8Bit().constData());
311311
YYERROR;
312312
}
313313
delete $1;
@@ -318,7 +318,7 @@ expression:
318318
{
319319
// @var is equivalent to var( "var" )
320320
QgsExpressionNode::NodeList* args = new QgsExpressionNode::NodeList();
321-
QgsExpressionNodeLiteral* literal = new QgsExpressionNodeLiteral( QString(*$1).mid(1) );
321+
QgsExpressionNodeLiteral* literal = new QgsExpressionNodeLiteral( QString( *$1 ).mid( 1 ) );
322322
args->append( literal );
323323
$$ = new QgsExpressionNodeFunction( QgsExpression::functionIndex( "var" ), args );
324324
delete $1;
@@ -343,7 +343,7 @@ exp_list:
343343
{
344344
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionNamedArgsError;
345345
parser_ctx->currentErrorType = errorType;
346-
exp_error(&yyloc, parser_ctx, "All parameters following a named parameter must also be named.");
346+
exp_error(&yyloc, parser_ctx, QObject::tr( "All parameters following a named parameter must also be named." ).toUtf8().constData() );
347347
delete $1;
348348
YYERROR;
349349
}

0 commit comments

Comments
 (0)