44#
55# SPDX-License-Identifier: MIT
66
7+ from __future__ import annotations
8+
79import json
810import re
911
@@ -106,7 +108,7 @@ def convert_atom(atom: str) -> str | bool:
106108 # For gettext: f == empty, t == empty, c == empty, e == empty
107109 return int (match .group (1 )) != 0
108110 raise ValueError (
109- f"Unable to convert the formula chunk '{ atom } ' from CLDR to gettext"
111+ f"Unable to convert the formula chunk '{ atom } ' from CLDR to gettext" ,
110112 )
111113
112114
@@ -131,7 +133,7 @@ def convert_formula(cldr_formula_and_examples: str) -> str:
131133 # Sanity checkign
132134 if "(" in cldr_formula or ")" in cldr_formula :
133135 raise ValueError (
134- f"Unable to convert the formula '{ cldr_formula } ': parenthesis handling not implemented"
136+ f"Unable to convert the formula '{ cldr_formula } ': parenthesis handling not implemented" ,
135137 )
136138
137139 # Blank formula for other
@@ -176,7 +178,8 @@ def reverse_formula(formula: str) -> str:
176178 return formula .replace (" == " , " != " ).replace (" || " , " && " ).strip ("()" )
177179
178180 if match := re .match (
179- r"^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$" , formula
181+ r"^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$" ,
182+ formula ,
180183 ):
181184 return f"{ match .group (1 )} != { match .group (2 )} || { match .group (3 )} == { match .group (4 )} "
182185
@@ -199,7 +202,7 @@ def merge_formulas(formulas: list[str]) -> str:
199202 for n in range (max_n - 1 , - 1 , - 1 ):
200203 part = formulas [n ]
201204
202- if not re .match ("^\([^()]+\)$" , part ):
205+ if not re .match (r "^\([^()]+\)$" , part ):
203206 part = f"({ part } )"
204207 formula = f"{ reduce_formula (part )} ? { n } : { formula } "
205208 if n > 0 :
@@ -210,7 +213,7 @@ def merge_formulas(formulas: list[str]) -> str:
210213
211214# Load language names
212215with open (
213- "modules/cldr-json/cldr-json/cldr-localenames-full/main/en/languages.json"
216+ "modules/cldr-json/cldr-json/cldr-localenames-full/main/en/languages.json" ,
214217) as handle :
215218 data = json .load (handle )
216219 LANGUAGES = {
@@ -279,5 +282,10 @@ with open("cldr.csv", "w") as handle:
279282 for code in sorted (LANGUAGES ):
280283 data = LANGUAGES [code ]
281284 handle .write (
282- "{},{},{},{}\n " .format (code , data ["name" ], data ["plurals" ], data ["formula" ])
285+ "{},{},{},{}\n " .format (
286+ code ,
287+ data ["name" ],
288+ data ["plurals" ],
289+ data ["formula" ],
290+ ),
283291 )
0 commit comments