Skip to content

Commit

Permalink
fix: wrong plural counts for some numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 1, 2024
1 parent a96f562 commit c10f6de
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
4 changes: 2 additions & 2 deletions PLURALS_DIFF.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ The Plurals column lists data in languages.csv which is used in Weblate
| ljp | Lampung Api | nplurals=2; plural=n != 1; | | | | |
| lki | Laki | nplurals=2; plural=n != 1; | | | | |
| lkt | Lakota | nplurals=1; plural=0; | ✔ | | | |
| lld | Ladin | nplurals=2; plural=(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2); | ✔ | | | |
| lld | Ladin | nplurals=3; plural=(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2); | ✔ | | | |
| lmn | Lambadi | nplurals=2; plural=n != 1; | | | | |
| lmo | Lombard | nplurals=2; plural=n != 1; | | | | |
| ln | Lingala | nplurals=2; plural=n > 1; | ✔ | | ✔ | ✔ |
Expand Down Expand Up @@ -602,7 +602,7 @@ The Plurals column lists data in languages.csv which is used in Weblate
| sat | Santali | nplurals=3; plural=n == 1 ? 0 : n == 2 ? 1 : 2; | ✔ | | nplurals=2; plural=(n != 1); | nplurals=2; plural=(n != 1); |
| sc | Sardinian | nplurals=2; plural=n != 1; | ✔ | | | |
| sck | Sadri | nplurals=2; plural=n != 1; | | | | |
| scn | Sicilian | nplurals=2; plural=(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2); | ✔ | | | nplurals=2; plural=(n != 1); |
| scn | Sicilian | nplurals=3; plural=(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2); | ✔ | | | nplurals=2; plural=(n != 1); |
| sco | Scots | nplurals=2; plural=n != 1; | | | ✔ | ✔ |
| sd | Sindhi | nplurals=2; plural=n != 1; | ✔ | | ✔ | ✔ |
| sdh | Kurdish (Southern) | nplurals=2; plural=n != 1; | ✔ | | | |
Expand Down
1 change: 1 addition & 0 deletions extraplurals.csv
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ lv,Latvian,3,(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1
se,Sami (Northern),2,(n != 1)
sl,Slovenian,4,(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0)
ro_MD,Moldavian,3,(n == 1) ? 0 : ((n == 0 || n != 1 && n % 100 >= 1 && n % 100 <= 19) ? 1 : 2)
scn,Sicilian,2,n != 1
4 changes: 2 additions & 2 deletions languages.csv
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ lij,Ligurian,2,n != 1
ljp,Lampung Api,2,n != 1
lki,Laki,2,n != 1
lkt,Lakota,1,0
lld,Ladin,2,(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)
lld,Ladin,3,(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)
lmn,Lambadi,2,n != 1
lmo,Lombard,2,n != 1
ln,Lingala,2,n > 1
Expand Down Expand Up @@ -596,7 +596,7 @@ sas,Sasak,2,n != 1
sat,Santali,3,n == 1 ? 0 : n == 2 ? 1 : 2
sc,Sardinian,2,n != 1
sck,Sadri,2,n != 1
scn,Sicilian,2,(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)
scn,Sicilian,3,(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)
sco,Scots,2,n != 1
sd,Sindhi,2,n != 1
sdh,Kurdish (Southern),2,n != 1
Expand Down
19 changes: 19 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# SPDX-License-Identifier: MIT

import csv
from gettext import c2py
from itertools import chain


def parse_csv(name):
Expand Down Expand Up @@ -59,3 +61,20 @@ for match in matching:
raise ValueError(
f"Mismatching plural form for {match}: {plural_our!r} != {plural_cldr!r}"
)


# Validate plural count
for code, _name, plural_count, plural_formula in languages.values():
plural = c2py(plural_formula)
# Get maximal plural
calculated = (
max(
plural(x)
for x in chain(range(-10, 200), [1000, 10000, 100000, 1000000, 10000000])
)
+ 1
)
if calculated != int(plural_count):
raise ValueError(
f"Mismatching plural count for {code}: {plural_count} != {calculated}"
)
4 changes: 2 additions & 2 deletions weblate_language_data/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3676,7 +3676,7 @@
# variant of the language. It could contain a region, age (Old, Middle, ...)
# or other variant.
_("Ladin"),
2,
3,
"(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)",
),
(
Expand Down Expand Up @@ -5395,7 +5395,7 @@
# variant of the language. It could contain a region, age (Old, Middle, ...)
# or other variant.
_("Sicilian"),
2,
3,
"(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)",
),
(
Expand Down
27 changes: 9 additions & 18 deletions weblate_language_data/plurals.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@
3,
"(n == 1) ? 0 : ((n == 0 || n != 1 && n % 100 >= 1 && n % 100 <= 19) ? 1 : 2)",
),
(
"scn",
# Translators: Language name for ISO code "scn". The parenthesis clarifies
# variant of the language. It could contain a region, age (Old, Middle, ...)
# or other variant.
_("Sicilian"),
2,
"n != 1",
),
)

CLDRPLURALS = (
Expand Down Expand Up @@ -289,15 +298,6 @@
3,
"(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)",
),
(
"lld",
# Translators: Language name for ISO code "lld". The parenthesis clarifies
# variant of the language. It could contain a region, age (Old, Middle, ...)
# or other variant.
_("Ladin"),
3,
"(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)",
),
(
"mt",
# Translators: Language name for ISO code "mt". The parenthesis clarifies
Expand Down Expand Up @@ -334,15 +334,6 @@
3,
"(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)",
),
(
"scn",
# Translators: Language name for ISO code "scn". The parenthesis clarifies
# variant of the language. It could contain a region, age (Old, Middle, ...)
# or other variant.
_("Sicilian"),
3,
"(n == 1) ? 0 : ((n != 0 && n % 1000000 == 0) ? 1 : 2)",
),
)

QTPLURALS = (
Expand Down

0 comments on commit c10f6de

Please sign in to comment.