Skip to content

Commit

Permalink
Handle QApplication::translate being called statically
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
Blake-Madden committed Jun 15, 2024
1 parent 9ef12d7 commit 12787d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/i18n_review.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace i18n_check
{ L"_T", L"Deprecated text macro can be removed. "
"(Add 'L' in front of string to make it double-byte.)" },
{ L"__T", L"Deprecated text macro can be removed. "
"(Add 'L' in front of string to make it double-byte.)" },
"(Add 'L' in front of string to make it double-byte.)" },
{ L"TEXT", L"Deprecated text macro can be removed. "
"(Add 'L' in front of string to make it double-byte.)" },
{ L"_TEXT", L"Deprecated text macro can be removed. "
Expand Down Expand Up @@ -439,6 +439,7 @@ namespace i18n_check
// Qt (note that NOOP functions actually do load something for translation, just not
// in-place)
L"tr", L"trUtf8", L"translate", L"QT_TR_NOOP", L"QT_TRANSLATE_NOOP",
L"QApplication::translate",
// KDE (ki18n)
L"i18n", L"i18np", L"i18ncp", L"i18nc", L"xi18n", L"xi18nc"
};
Expand Down Expand Up @@ -903,6 +904,7 @@ namespace i18n_check
// can be context strings that should not be translatable
if ( // Qt
(functionName == L"translate" && parameterPosition == 0) ||
(functionName == L"QApplication::translate" && parameterPosition == 0) ||
(functionName == L"tr" && parameterPosition == 1) ||
(functionName == L"trUtf8" && parameterPosition == 1) ||
(functionName == L"QT_TRANSLATE_NOOP" && parameterPosition == 0) ||
Expand Down
18 changes: 18 additions & 0 deletions tests/cpptests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,24 @@ QLabel *label = new QLabel(
CHECK(cpp.get_unsafe_localizable_strings().size() == 0);
}

SECTION("QApplication::translate")
{
cpp_i18n_review cpp;
const wchar_t* code = LR"(QString test = qApp->translate("SomeContext", "source content");
QString test = QApplication::translate("SomeContext", "more source content");)";
cpp(code, L"");
cpp.review_strings();
REQUIRE(cpp.get_localizable_strings().size() == 2);
CHECK(cpp.get_localizable_strings()[0].m_string == L"source content");
CHECK(cpp.get_localizable_strings()[1].m_string == L"more source content");
CHECK(cpp.get_not_available_for_localization_strings().size() == 0);
REQUIRE(cpp.get_internal_strings().size() == 2);
// context portion of translate()
CHECK(cpp.get_internal_strings()[0].m_string == L"SomeContext");
CHECK(cpp.get_internal_strings()[1].m_string == L"SomeContext");
CHECK(cpp.get_unsafe_localizable_strings().size() == 0);
}

SECTION("QT_TR_NOOP")
{
cpp_i18n_review cpp;
Expand Down

0 comments on commit 12787d8

Please sign in to comment.