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

Java Format check fails for out of order parameters #5033

Closed
Ch4t4r opened this issue Dec 14, 2020 · 4 comments
Closed

Java Format check fails for out of order parameters #5033

Ch4t4r opened this issue Dec 14, 2020 · 4 comments
Labels
question This is more a question for the support than an issue.

Comments

@Ch4t4r
Copy link

Ch4t4r commented Dec 14, 2020

Describe the bug

I use Weblate to translate my Android app.
In texts with positional arguments (%1s, %2s, ...) the Java Format check fails when the order in which they appear is not the same as in the source string.
An example source is The quick brown %1s jumps over the lazy %2s with %3s, an example (and valid) target could be Der träge %2s wird vom %1s mit einem %3s übersprungen. It would result in the following error:

Java format
Following format strings are missing: %1s, %2s
Following format strings are extra: %1s, %2s

Expected behavior

I'm not exactly sure whether this is worth fixing or not. In some cases the check would help catch formatted strings which are unintentionally out of order, however there are some languages where they are always going to be out of order.
I'll leave that up to you to decide. I can simply dismiss the error where applicable.

Server configuration and status

Weblate installation: Docker, version 4.3.2

@nijel nijel added the question This is more a question for the support than an issue. label Dec 14, 2020
@github-actions
Copy link

This issue looks more like a support question than an issue. We strive to answer these reasonably fast, but purchasing the support subscription is not only more responsible and faster for your business but also makes Weblate stronger. In case your question is already answered, making a donation is the right way to say thank you!

@nijel
Copy link
Member

nijel commented Dec 14, 2020

Your format strings are wrong - these do not allow reordering, the number defines minimal width of the string. You should be using %1$s instead of %1s. See https://medium.com/better-programming/formatting-strings-with-java-2281d40accce

@Ch4t4r
Copy link
Author

Ch4t4r commented Dec 14, 2020

TIL what the $ is for. I've always (wrongly) assumed the numbers are for the position.
Thanks!

I'm going to close this then. Just a small side question, is it possible for the error message to be a bit more precise in this case (missing format args=extra format args)?

@Ch4t4r Ch4t4r closed this as completed Dec 14, 2020
@github-actions
Copy link

The issue you have reported is resolved now. If you don’t feel it’s right, please follow it’s labels to get a clue and take further steps.

  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This is more a question for the support than an issue.
Projects
None yet
Development

No branches or pull requests

2 participants