Skip to content

Commit ea43838

Browse files
m-kuhnDelazJ
authored andcommitted
Make expression parser output translatable
(cherry picked from commit 3dd3609)
1 parent 89185f6 commit ea43838

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
@@ -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
}
@@ -240,13 +240,13 @@ expression:
240240
QString expectedMessage;
241241
if ( func->params() == func->minParams() )
242242
{
243-
expectedMessage = QStringLiteral( "Expected %1 but got %2." ).arg( QString::number( func->params() ), QString::number( $3->count() ) );
243+
expectedMessage = QObject::tr( "Expected %1 but got %2." ).arg( QString::number( func->params() ), QString::number( $3->count() ) );
244244
}
245245
else
246246
{
247-
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() ) );
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, QStringLiteral( "%1 function is called with wrong number of arguments. %2" ).arg( QgsExpression::Functions()[fnIndex]->name(), expectedMessage ).toUtf8().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() );
250250
delete $3;
251251
YYERROR;
252252
}
@@ -263,7 +263,7 @@ expression:
263263
{
264264
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
265265
parser_ctx->currentErrorType = errorType;
266-
exp_error(&yyloc, parser_ctx, "Function is not known");
266+
exp_error(&yyloc, parser_ctx, QObject::tr( "Function is not known" ).toUtf8().constData() );
267267
YYERROR;
268268
}
269269
// 0 parameters is expected, -1 parameters means leave it to the
@@ -272,7 +272,7 @@ expression:
272272
{
273273
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs;
274274
parser_ctx->currentErrorType = errorType;
275-
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() );
276276
YYERROR;
277277
}
278278
$$ = new QgsExpressionNodeFunction(fnIndex, new QgsExpressionNode::NodeList());
@@ -304,7 +304,7 @@ expression:
304304
{
305305
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionUnknown;
306306
parser_ctx->currentErrorType = errorType;
307-
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());
308308
YYERROR;
309309
}
310310
delete $1;
@@ -315,7 +315,7 @@ expression:
315315
{
316316
// @var is equivalent to var( "var" )
317317
QgsExpressionNode::NodeList* args = new QgsExpressionNode::NodeList();
318-
QgsExpressionNodeLiteral* literal = new QgsExpressionNodeLiteral( QString(*$1).mid(1) );
318+
QgsExpressionNodeLiteral* literal = new QgsExpressionNodeLiteral( QString( *$1 ).mid( 1 ) );
319319
args->append( literal );
320320
$$ = new QgsExpressionNodeFunction( QgsExpression::functionIndex( "var" ), args );
321321
delete $1;
@@ -340,7 +340,7 @@ exp_list:
340340
{
341341
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionNamedArgsError;
342342
parser_ctx->currentErrorType = errorType;
343-
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() );
344344
delete $1;
345345
YYERROR;
346346
}

0 commit comments

Comments
 (0)