Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish ToDo in localizationParameterMustIncludeAString #11793

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -158,17 +159,17 @@ void findObsoleteLocalizationKeys() throws IOException {
@Test
void localizationParameterMustIncludeAString() throws IOException {
// Must start or end with "
// No string concatenation, just literal string, please check https://devdocs.jabref.org/code-howtos/localization.html
// Localization.lang("test"), Localization.lang("test" + var), Localization.lang(var + "test")
// TODO: Localization.lang(var1 + "test" + var2) not covered
// Localization.lang("Problem downloading from %1", address)
// Localization.lang(var1 + "test" + var2), Localization.lang("Problem downloading from %1", address)
Set<LocalizationEntry> keys = LocalizationParser.findLocalizationParametersStringsInJavaFiles(LocalizationBundleForTest.LANG);
for (LocalizationEntry e : keys) {
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\""), "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\"") || StringUtils.countMatches(e.getKey(), "\"") == 2, "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());
}

keys = LocalizationParser.findLocalizationParametersStringsInJavaFiles(LocalizationBundleForTest.MENU);
for (LocalizationEntry e : keys) {
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\""), "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\"") || StringUtils.countMatches(e.getKey(), "\"") == 2, "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One day later, I have a more clear mind.

We have

Localization.lang("Added group \"%0\".", group.getName())

Localiatzion:

Added group "%0".

It has two ". This is OK.

The updated code of you checks for two of them. It should match. It does not.

I think, more debugging and thinking is required here.

Maybe, a test for the test needs to be developed?

It is OK for a coding excercise, but not really required for JabRef. We have many other user-facing issues. We should work on these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One day later, I have a more clear mind.

We have

Localization.lang("Added group \"%0\".", group.getName())

Localiatzion:

Added group "%0".

It has two ". This is OK.

The updated code of you checks for two of them. It should match. It does not.

I think, more debugging and thinking is required here.

Maybe, a test for the test needs to be developed?

It is OK for a coding excercise, but not really required for JabRef. We have many other user-facing issues. We should work on these.

OK, I'll try to find a proper user-facing issue to solve from tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localization.lang("Added group "%0".", group.getName())

this case can be covered by e.getKey().startsWith("\""), so that is why my code can pass the unit test phase in CI/CD workflow or local test run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The || in the condition feels wrong.

Localization.lang(var1 + "test" + var2)

Matches this condition, but is forbidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The || in the condition feels wrong.

Localization.lang(var1 + "test" + var2)

Matches this condition, but is forbidden.

the original ToDo is TODO: Localization.lang(var1 + "test" + var2) not covered, I thought it means Localization.lang(var1 + "test" + var2) is not forbidden.

Then just delete the ToDo in comment like option 2 in #11784 or I just close this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry to have kept you waiting. We put through a refinement at #11820 and thus decided on closing this one.

Thanks for taking this up!

}
}

Expand Down
Loading