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

.stringdict plural forms incorrect #12209

Closed
2 tasks done
dwaynebailey opened this issue Aug 6, 2024 · 7 comments · Fixed by #12219
Closed
2 tasks done

.stringdict plural forms incorrect #12209

dwaynebailey opened this issue Aug 6, 2024 · 7 comments · Fixed by #12219
Assignees
Labels
bug Something is broken.
Milestone

Comments

@dwaynebailey
Copy link
Contributor

dwaynebailey commented Aug 6, 2024

Describe the issue

Comparing Android to iOS plural forms for Afrikaans. They are different while both claiming to be using CLDR. I suspect this is only a visual anomaly but it is enough to confuse translators.

Android:

Android
integer -> index -> cldr form
0 -> 0 -> other
1 -> 1 -> one
2 -> 0 -> other
3 -> 0 -> other
4 -> 0 -> other
5 -> 0 -> other
10 -> 0 -> other

iOS:

iOS
integer -> index -> cldr form
0 -> 0 -> zero
1 -> 2 -> other
2 -> 1 -> one
3 -> 1 -> one
4 -> 1 -> one
5 -> 1 -> one
10 -> 1 -> one

I've traced the problem here:
https://github.com/WeblateOrg/weblate/blob/stable/weblate/lang/data.py#L235
but I'm not sure:

  1. How these where derived
  2. If they are merely informational and for providing the CLDR examples, or
  3. If they are actually what Android uses

I already tried

  • I've read and searched the documentation.
  • I've searched for similar filed issues in this repository.

Steps to reproduce the behavior

  1. Ensure you have iOS stringdict and Android projects for similar strings
  2. Enable Afrikaans (af) which has two forms (one, other)
  3. Compare the suggested numeric help between Android and iOS one and other are swapped

Expected behavior

Honour the CLDR forms in iOS plurals https://www.unicode.org/cldr/charts/42/supplemental/language_plural_rules.html#af

The correct formula would be: n==0 ? 0 : n==1 ? 1 : 2

Screenshots

No response

Exception traceback

No response

How do you run Weblate?

weblate.org service

Weblate versions

No response

Weblate deploy checks

No response

Additional context

No response

@nijel
Copy link
Member

nijel commented Aug 6, 2024

See #6368

@dwaynebailey
Copy link
Contributor Author

@nijel that seems to be about zero, this is about one and other being swapped

@dwaynebailey
Copy link
Contributor Author

Something similar occurs for n>1 equations, note the actual output is correct but the numeric examples for one and other are swapped:

Persian (fa) Android: https://hosted.weblate.org/translate/organicmaps/android/fa/?checksum=e8e3cb8cdbc14c55
Persian (fa) iOS: https://hosted.weblate.org/translate/organicmaps/wip-ios-plurals-please-dont-use/fa/?checksum=efcf782307b0b6f3

@nijel
Copy link
Member

nijel commented Aug 6, 2024

Sorry, I didn't understand this from the initial post.

These are only examples shown in Weblate, it should not affect anything else. But you're right that most of (if not all) the formulas have messed up ordering:

FORMULA_WITH_ZERO = {
"0": "n==0 ? 0 : 1",
"n > 1": "n==0 ? 0 : n>1 ? 1 : 2",
"n != 1": "n==0 ? 0 : n!=1 ? 1 : 2",
"(n == 0 || n == 1) ? 0 : ((n >= 2 && n <= 10) ? 1 : 2)": "n == 0 ? 0 : n == 1 ? 1 : ((n >= 2 && n <= 10) ? 2 : 3)",
"n == 1 ? 0 : n == 2 ? 1 : 2": "n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : 3",
"n==1 || n%10==1 ? 0 : 1": "n == 0 ? 0 : n==1 || n%10==1 ? 1 : 2",
"n==1 ? 0 : n==2 ? 1 : 2": "n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : 3",
"(n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3": "n==0 ? 0 : (n==1 || n==11) ? 1 : (n==2 || n==12) ? 2 : (n > 2 && n < 20) ? 3 : 4",
"n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9)": "n==0 ? 0 : n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9) ? 1: 2",
"n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2": "n==0 ? 0 : n==1 ? 1 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 2 : 3",
"(n == 1) ? 0 : ((n == 0 || n % 100 >= 2 && n % 100 <= 19) ? 1 : 2)": "n==0 ? 0 : (n == 1) ? 1 : ((n == 0 || n % 100 >= 2 && n % 100 <= 19) ? 2 : 3)",
"n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2": "n==0 ? 0 : n==1 ? 1 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 3",
"(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2": "n==0 ? 0 : (n==1) ? 1 : (n>=2 && n<=4) ? 2 : 3",
"(n == 1) ? 0 : ((n == 2) ? 1 : 2)": "n==0 ? 0 : (n == 1) ? 1 : ((n == 2) ? 2 : 3)",
"n==1 ? 0 : n==0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3": "n==0 ? 0 : n==1 ? 1 : ( n%100>1 && n%100<11) ? 2 : (n%100>10 && n%100<20 ) ? 3 : 4",
"n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2": "n==0 ? 0 : n%10==1 && n%100!=11 ? 1 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 3",
"(n == 1) ? 0 : ((n == 2) ? 1 : ((n > 10 && n % 10 == 0) ? 2 : 3))": "n==0 ? 0 : (n == 1) ? 1 : ((n == 2) ? 2 : ((n > 10 && n % 10 == 0) ? 3 : 4))",
"n==1 ? 0 : n==2 ? 1 : (n>2 && n<7) ? 2 :(n>6 && n<11) ? 3 : 4": "n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : (n>2 && n<7) ? 3 :(n>6 && n<11) ? 4 : 5",
"(n % 100 == 1) ? 0 : ((n % 100 == 2) ? 1 : ((n % 100 == 3 || n % 100 == 4) ? 2 : 3))": "n==0 ? 0 : (n % 100 == 1) ? 1 : ((n % 100 == 2) ? 2 : ((n % 100 == 3 || n % 100 == 4) ? 3 : 4))",
"n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3": "n==0 ? 0 : n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 4",
"n % 10 != 1 || n % 100 == 11": "n==0 ? 0 : n % 10 != 1 || n % 100 == 11 ? 1 :2",
"(n % 10 == 1 && (n % 100 < 11 || n % 100 > 19)) ? 0 : ((n % 10 >= 2 && n % 10 <= 9 && (n % 100 < 11 || n % 100 > 19)) ? 1 : 2)": "n==0 ? 0 : (n % 10 == 1 && (n % 100 < 11 || n % 100 > 19)) ? 1 : ((n % 10 >= 2 && n % 10 <= 9 && (n % 100 < 11 || n % 100 > 19)) ? 2 : 3)",
"n >= 2 && (n < 11 || n > 99)": "n==0 ? 0 : n >= 2 && (n < 11 || n > 99) ? 1 : 2",
"(n % 10 == 1) ? 0 : ((n % 10 == 2) ? 1 : ((n % 100 == 0 || n % 100 == 20 || n % 100 == 40 || n % 100 == 60 || n % 100 == 80) ? 2 : 3))": "n==0 ? 0 : (n % 10 == 1) ? 1 : ((n % 10 == 2) ? 2 : ((n % 100 == 0 || n % 100 == 20 || n % 100 == 40 || n % 100 == 60 || n % 100 == 80) ? 3 : 4))",
"(n % 10 == 1 && n % 100 != 11 && n % 100 != 71 && n % 100 != 91) ? 0 : ((n % 10 == 2 && n % 100 != 12 && n % 100 != 72 && n % 100 != 92) ? 1 : ((((n % 10 == 3 || n % 10 == 4) || n % 10 == 9) && (n % 100 < 10 || n % 100 > 19) && (n % 100 < 70 || n % 100 > 79) && (n % 100 < 90 || n % 100 > 99)) ? 2 : ((n != 0 && n % 1000000 == 0) ? 3 : 4)))": "n==0 ? 0 : (n % 10 == 1 && n % 100 != 11 && n % 100 != 71 && n % 100 != 91) ? 1 : ((n % 10 == 2 && n % 100 != 12 && n % 100 != 72 && n % 100 != 92) ? 2 : ((((n % 10 == 3 || n % 10 == 4) || n % 10 == 9) && (n % 100 < 10 || n % 100 > 19) && (n % 100 < 70 || n % 100 > 79) && (n % 100 < 90 || n % 100 > 99)) ? 3 : ((n != 0 && n % 1000000 == 0) ? 4 : 5)))",
"n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2": "n==0 ? 0 : n%10==1 && n%100!=11 ? 1 : 2",
"(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)": "(n == 0) ? 0 : (n == 1) ? 1 : ((n != 0 && n % 1000000 == 0) ? 2 : 3)",
"(n == 0 || n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)": "(n == 0) ? 0 : (n == 1) ? 1 : ((n != 0 && n % 1000000 == 0) ? 2 : 3)",
"(n == 1) ? 0 : ((n == 2) ? 1 : ((n == 0 || n % 100 >= 3 && n % 100 <= 10) ? 2 : ((n % 100 >= 11 && n % 100 <= 19) ? 3 : 4)))": "(n == 0) ? 0 : (n == 1) ? 1 : ((n == 2) ? 2 : ((n == 0 || n % 100 >= 3 && n % 100 <= 10) ? 3 : ((n % 100 >= 11 && n % 100 <= 19) ? 4 : 5)))",
}

I probably generated these wrongly back then.

@nijel nijel added the bug Something is broken. label Aug 6, 2024
@dwaynebailey
Copy link
Contributor Author

These are only examples shown in Weblate, it should not affect anything else. But you're right that most of (if not all) the formulas have messed up ordering:

That is a relief. I'll see what I can do to produce a PR, if not for all of them at least for the simple common forms

@nijel
Copy link
Member

nijel commented Aug 6, 2024

It is likely that all of them are messed up, I did somehow generated them and apparently that was broken.

Looking at it, broken might be only the ones which don't have explicit plural numbers in the original formula. The problem with the conversion is that it turned n > 1 into n > 1 ? 0 : 1 but it actually means n > 1 ? 1 : 0. Then the n==0 was added and number increased.

dwaynebailey added a commit to dwaynebailey/weblate that referenced this issue Aug 7, 2024
Only: n!=1 and n>1 as they're the most common.

Partial fix for WeblateOrg#12209
@nijel nijel added this to the 5.7 milestone Aug 7, 2024
@nijel nijel linked a pull request Aug 7, 2024 that will close this issue
5 tasks
nijel pushed a commit that referenced this issue Aug 7, 2024
Only: n!=1 and n>1 as they're the most common.

Partial fix for #12209
Copy link

github-actions bot commented Aug 7, 2024

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • 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
bug Something is broken.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants