44with month names (full and abbreviated) based on the list of
55target languages.
66
7- Run this script with hatch to regeneate the file::
7+ Run this script with hatch to regenerate the file::
88
99 hatch run codegen:generate
1010
@@ -48,7 +48,7 @@ def main():
4848 for width in ["wide" , "abbreviated" ]:
4949 for month_num , month_name in get_month_names (width , locale = lang ).items ():
5050 # some locales use a . on the shortened month; let's ignore that
51- month_name = month_name .strip ("." )
51+ month_name = month_name .strip ("." ). lower ()
5252 # In some cases different languages have the same abbreviations;
5353 # in some cases, abbreviated and full are the same.
5454 # Only add if not already present, to avoid redundancy
@@ -59,11 +59,12 @@ def main():
5959 outfile .write (warning_text )
6060
6161 # for each numeric month, generate a rule with all variant names:
62- # month_1: " January" | " Jan" ...
62+ # month_1: / January| Jan/i
6363 for i , names in all_month_names .items ():
64- # combine all names in an OR string
65- or_names = " | " .join (f'"{ m } "' for m in names )
66- outfile .write (f"month_{ i } : { or_names } \n " )
64+ # combine all names in a case-insensitive OR regex
65+ # sort shortest variants last to avoid partial matches hitting first
66+ or_names = "|" .join (sorted (names , key = len , reverse = True ))
67+ outfile .write (f"month_{ i } : /({ or_names } )/i\n " )
6768
6869 print (
6970 f"Successfully regenerated { MONTH_GRAMMAR_FILE .relative_to (pathlib .Path .cwd ())} "
0 commit comments