Skip to content

Commit 495365e

Browse files
committed
fix(export-cldr): corrected plural export logic
This seems never used, but the operator was inverted.
1 parent 11e724c commit 495365e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/export-cldr.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def expand_chunk(what: str, op: str, value: str) -> str:
4545
if (end - start) == 1:
4646
if op == "==":
4747
return f"({what} == {start} || {what} == {end})"
48-
return f"{what} != {start} && {what} == {end}"
48+
return f"{what} != {start} && {what} != {end}"
4949
if op == "==":
5050
return f"{what} >= {start} && {what} <= {end}"
5151
if what == "n" and start <= 0:
@@ -117,7 +117,7 @@ def convert_formula(cldr_formula_and_examples: str) -> str | bool:
117117
raise ValueError(f"Invalid CLDR category rule: {cldr_formula_and_examples}")
118118
cldr_formula = match.group(1).strip()
119119

120-
# Sanity checkign
120+
# Sanity checking
121121
if "(" in cldr_formula or ")" in cldr_formula:
122122
raise ValueError(
123123
f"Unable to convert the formula '{cldr_formula}': parenthesis handling not implemented",
@@ -242,6 +242,8 @@ class LanguageDict(TypedDict, total=False):
242242

243243

244244
# Parse plurals
245+
NON_MERGE_PLURALS = 2
246+
245247
with open("modules/cldr-json/cldr-json/cldr-core/supplemental/plurals.json") as handle:
246248
data = json.load(handle)
247249
for cldr_code, categories in data["supplemental"]["plurals-type-cardinal"].items():
@@ -255,8 +257,8 @@ class LanguageDict(TypedDict, total=False):
255257
LANGUAGES[code]["formula"] = "0"
256258
continue
257259
formulas = [convert_formula(category) for category in categories.values()]
258-
if len(categories) == 2: # noqa: PLR2004
259-
LANGUAGES[code]["plurals"] = 2
260+
if len(categories) == NON_MERGE_PLURALS:
261+
LANGUAGES[code]["plurals"] = NON_MERGE_PLURALS
260262
LANGUAGES[code]["formula"] = reduce_formula(reverse_formula(formulas[0]))
261263
else:
262264
cleaned_up_formula = [

0 commit comments

Comments
 (0)