Home > Back-end >  Plural translation strings not found when using QCoreApplication::translate()
Plural translation strings not found when using QCoreApplication::translate()

Time:12-06

When I declare a translatable string with QCoreApplication::translate() without plural, such as :

QCoreApplication::translate("Context", "[A] removed [B] item(s)");

the string is correctly detected my Qt5 Linguist after running lupdate.

When I declare the same string using plurals, such as :

QCoreApplication::translate("Context", "[A] removed %n item(s)", "", static_cast<int>(items));

the string is not detected anymore my lupdate.

This doesn't apply to the use of tr() calls, their plurals are correctly reported my lupdate.

CodePudding user response:

The issue is the static_cast<>. Moving the cast to a separate line resolved the issue :

int itemsAsInt = static_cast<int>(items);
QCoreApplication::translate("Context", "[A] removed %n item(s)", "", itemsAsInt);
  • Related