Translate the filter string error at display time (#5283)

Keep the parser message untranslated so FilterStringLog stays in the source
language, and format the user-facing text in error() instead. That gives both
consumers what they need without localizing the log.

Q_DECLARE_TR_FUNCTIONS provides the tr() context without deriving from QObject,
which would have deleted copy/move assignment and broken the by-value uses in
PlayerActions and ViewZone. Drop the unreachable line-number branch; peglib
reports 1-based lines, so every message keeps master's "position" wording.

Co-authored-by: Lukas Brübach <44814898+BruebachL@users.noreply.github.com>
This commit is contained in:
ebbit1q 2026-11-07 16:26:31 +01:00 • committed by GitHub
parent 7487a383a3
commit 4b224f7fe5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 6 deletions

View file

@ -279,6 +279,22 @@ TEST_F(SetQuery, ComparisonMatchesByReleaseDate)
EXPECT_FALSE(FilterString("set<EOE").check(inBothSets));
}
TEST(FilterStringError, InvalidExpressionIsInvalidAndReportsAPosition)
{
const FilterString filter("t:(");
EXPECT_FALSE(filter.valid());
EXPECT_TRUE(filter.error().contains("position")) << "unexpected error text: " << filter.error().toStdString();
}
TEST(FilterStringError, ValidExpressionHasNoError)
{
const FilterString filter("t:creature");
EXPECT_TRUE(filter.valid());
EXPECT_TRUE(filter.error().isEmpty());
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);