Skip to content

Commit

Permalink
Fix regressions from changing regex expression and searching for %%
Browse files Browse the repository at this point in the history
Use proper check for finding %%
  • Loading branch information
Blake-Madden committed Jan 22, 2025
1 parent f6b0a08 commit 75b9336
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/i18n_review.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,14 +1419,14 @@ namespace i18n_check
while (std::regex_search(currentTextBlock.cbegin(), currentTextBlock.cend(),
stPositions, l10nStringNonStringLiteralArgRegEx))
{
currentTextBlock = currentTextBlock.substr(stPositions.position());
currentBlockOffset += stPositions.position();
currentTextBlock = currentTextBlock.substr(stPositions.position(1));
currentBlockOffset += stPositions.position(1);
if (stPositions.size() >= 3 &&
// only something like LR, L, u8, etc. can be in front of a quote
stPositions[1].length() > 2 && stPositions[2].str() != L"\"")
stPositions[2].length() > 2 && stPositions[3].str() != L"\"")
{
m_suspect_i18n_usage.push_back(string_info(
stPositions[1].str(),
stPositions[2].str(),
string_info::usage_info(
string_info::usage_info::usage_type::function,
_(L"Only string literals should be passed to _() and wxPLURAL() functions.")
Expand Down Expand Up @@ -2330,13 +2330,6 @@ namespace i18n_check
}

i18n_string_util::remove_hex_color_values(strToReview);
// allow %% even when not allowing punctuation-only strings as the
// percent symbol in a formatted string can be localized to something else
// (or moved to a different position in the string)
if (strToReview.find(L"%%") != std::wstring::npos)
{
return std::make_pair(false, strToReview.length());
}
i18n_string_util::remove_printf_commands(strToReview);
i18n_string_util::remove_escaped_unicode_values(strToReview);
string_util::trim(strToReview);
Expand All @@ -2348,7 +2341,8 @@ namespace i18n_check
{
chr = L' ';
}
if (allPunctOrSpaces && !std::iswdigit(chr) && !std::iswpunct(chr))
if (allPunctOrSpaces && !std::iswdigit(chr) && !std::iswpunct(chr) &&
!std::iswspace(chr))
{
allPunctOrSpaces = false;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/i18nstringtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ TEST_CASE("untranslatable", "[i18nreview]")
CHECK(reviewer.is_untranslatable_string(L"#somethingElse", false).first);
// CSS
CHECK(reviewer.is_untranslatable_string(L"height:%dpx;", false).first);
// formatted percentage symobl should be translatable
CHECK_FALSE(reviewer.is_untranslatable_string(L"%s%% (%s)", false).first);
CHECK_FALSE(reviewer.is_untranslatable_string(L"%s%%\n(%s)", false).first);
CHECK_FALSE(reviewer.is_untranslatable_string(L"%s%%\\n(%s)", false).first);
}

TEST_CASE("translatable", "[i18nreview]")
Expand Down

0 comments on commit 75b9336

Please sign in to comment.